1
0
Fork 0
mirror of https://github.com/notwa/rc synced 2024-11-05 06:39:02 -08:00
rc/home/vimrc

468 lines
13 KiB
VimL
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

" make vim unusable for anyone else
" from the get-go, we assume version >= 703
set nocompatible " screw vi
" hacks {{{1
if has('multi_byte')
scriptencoding utf-8 " allow it in this script
set termencoding=utf-8 " and this terminal supports it
set encoding=utf-8 " and the default file is in it
endif
" awful things
if has("win32")
" assume directory structure:
" something/anything/.vimrc " this was passed to vim by the -u switch
" something/vim/
" something/vim/after
let $MYVIMRC=expand('<sfile>')
let g:rcvim=expand('<sfile>:p:h:h').'/vim'
let msys='/MinGW/msys/1.0/bin'
set shellcmdflag=-c
set shellxquote=\"
set shellslash
if !exists('win32_once')
let win32_once=1
if exists('msys') " note: true for gvim as well
if isdirectory(msys)
let $PATH.=';'.msys
let &shell=msys.'/bash.exe'
else
let $PATH='/usr/local/bin;/usr/bin;/bin;'.$PATH
let &shell='/cygwin/bin/zsh.exe'
endif
endif
let &runtimepath=g:rcvim.','.&runtimepath.','.g:rcvim.'/after'
endif
else
let g:rcvim=$HOME.'/.vim'
endif
let &backupdir=g:rcvim.'/backup' " stash tilde files elsewhere
" the double slash at the end dumps the path of the file for uniqueness
let &directory=g:rcvim.'/swp//' " stash swap files too
let &undodir=g:rcvim.'/undo/' " undo files are cool
try | call mkdir(&backupdir, "p") | catch /E739/ | endtry
try | call mkdir(&directory, "p") | catch /E739/ | endtry
try | call mkdir(&undodir, "p") | catch /E739/ | endtry
if (&term =~ "^xterm") " enable colors on any xterm
let &t_Co=256
let &t_AF="\e[38;5;%dm"
let &t_AB="\e[48;5;%dm"
endif
" main config {{{1
if has('syntax')
syntax enable " required for folding as well
set hlsearch " highlight search results
endif
let g:python_highlight_builtin_funcs=1
if has('gui_running')
set guioptions-=M " skip loading $VIMRUNTIME/menu.vim
set guioptions-=m " hide menu which isn't loaded anyway
set guioptions-=T " hide toolbar
set guioptions-=r " hide scrollbar
if has("gui_gtk2")
set guifont=Consolas\ 11
else
set guifont=Consolas:h9
end
set columns=84
set lines=36
cd $HOME " might not be ideal...
endif
if has('title') | set title | endif " terminal title
set history=512 " command lines to remember
set number " lines
set ruler " write out the cursor position
set showcmd " show number of lines/etc. selected
set lazyredraw " when executing macros, untyped things
set shortmess=atI " be less verbose and shut up vim
set suffixes=.bak,~,.swp,.o,.log,.out " lower tab-completion priority
set noerrorbells visualbell t_vb= " disable bells
set scrolloff=3 " row context during scrolling
set sidescrolloff=2 " col context during scrolling
set incsearch " show first search result as we type
set ignorecase " insensitive searching
set smartcase " except when uppercase is used
set infercase " use existing case when ins-completing
set tabstop=8 shiftwidth=8 smarttab " 8 space tabs
set virtualedit=block " allow cursor anywhere in visual block
set foldmethod=marker " (performance issues with other methods)
set foldlevelstart=99 " start with everything unfolded...?
let c_syntax_for_h=1 " use C highlighting for .h files
set nowrap " word wrapping is pretty weak in vim
set ffs=unix,dos " ffs indeed
set nobomb " bombs are bad ok
set undofile " remember undos across files/sessions
set diffopt+=iwhite " ignore whitespace in diff command
set ttimeoutlen=50 " make changing modes a bit snappier
if has('mksession')
set sessionoptions=blank,buffers,curdir,options,folds,tabpages,winsize,resize,winpos
end
if 0
set autoindent " when creating newline, use same indent
if has('smartindent')
set smartindent " automatic indents with a lot of stuff
endif
endif " it's really just annoying though
if has('wildignore')
" a bunch of stuff that may or may not do any good
set wildignore=""
set wildignore+=.git,.svn,.hg,pkg,tmp,crap
set wildignore+=*.bak,*.tmp,*.log,*.cache,
set wildignore+=Desktop.ini,Thumbs.db,*.lnk,.DS_Store
set wildignore+=*.zip,*.tar,*.tar.*,
set wildignore+=*.suo,*.sln,*.pch,*.pdb,*.pgc,*.pgd
set wildignore+=*.o,*.obj,*.elf,*.lib,*.a,*.dll,*.so,*.so.*,*.exe,*.out
set wildignore+=__pycache__,*.pyc,*.pyo,*.pyd
set wildignore+=*.gem,.bundle
set wildignore+=CMake*,cmake_install.cmake,install_manifest.txt
endif
" autocmd {{{1
fu! SaveSession()
let sf=g:rcvim.'/.session.vim'
execute 'mksession! '.sf
endf
fu! LoadSession()
let sf=g:rcvim.'/.session.vim'
if filereadable(sf)
execute 'so '.sf
endif
endf
fu! KillSession()
let sf=g:rcvim.'/.session.vim'
call delete(sf)
endf
fu! TabEight()
setlocal tabstop=8 shiftwidth=8 noexpandtab softtabstop=0
endf
fu! TabFour()
setlocal tabstop=8 shiftwidth=4 expandtab softtabstop=4
endf
fu! TabTwo()
setlocal tabstop=2 shiftwidth=2 expandtab
endf
" set TabFour as default
set tabstop=8 shiftwidth=4 expandtab softtabstop=4
if has('autocmd')
augroup tabs
au!
au BufRead,BufNewFile *.c,*.h,*.cpp,*.hpp,*.cc,*.hh call TabEight()
au BufRead,BufNewFile PKGBUILD call TabTwo()
au FileType ruby call TabTwo()
au BufRead,BufNewFile *.bt,*.1sc call TabFour()
augroup END
augroup whatever
au!
au BufRead,BufNewFile *.lib setlocal ft=spice
au BufRead,BufNewFile *.bt setlocal ft=c
au BufRead,BufNewFile *.1sc setlocal ft=c
au BufRead,BufNewFile *.asm setlocal ft=lips
augroup END
augroup nocomment
au!
au FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
augroup sessions
au!
au VimEnter * call LoadSession()
augroup END
augroup nobells " good lord vim you are archaic
au!
au GUIEnter * set vb t_vb=
augroup END
augroup reload
au!
"au BufWritePost .vimrc,_vimrc,vimrc so $MYVIMRC
augroup END
fu! ResCur() " attempt to preserve cursor position
if line("'\"") > 1 && line("'\"") <= line("$")
normal! g`"
return 1
endif
endf
augroup resCur
au!
au BufWinEnter * call ResCur()
augroup END
endif
" keys/binds {{{1
set backspace=eol,start,indent " make backspace useful
" tab completion in command-line
if has('wildmenu') | set wildmenu | endif
" easy indent/unindent
nn <tab> >>
nn <s-tab> <<
" indentation without ending selection
vn <silent> <tab> >gv
vn <silent> <s-tab> <gv
" might make return useful
"nn <s-cr> J
"nn <c-cr> dd
" oh wait, terminals don't do that...
fu! Inn(q)
" bind both normal and insert modes
let args=split(a:q, '^\s*\(<[^>]\+>\s\+\)\+\zs')
exec 'nn '.args[0].' '.args[1]
exec 'ino '.args[0].' <c-o>'.args[1]
endf
com! -nargs=+ Inn call Inn(<q-args>)
Inn <F5> :w<cr>
Inn <F8> :e<cr>
Inn <F10> :bd<cr>
Inn <c-F5> :w!<cr>
Inn <c-F8> :e!<cr>
Inn <c-F10> :bd!<cr>
Inn <s-F5> :wall<cr>
"Inn <s-F8> :tab ball<cr>
Inn <s-F10> :call KillSession()<cr>:qall<cr>
Inn <c-s-F10> :call KillSession()<cr>:qall!<cr>
" np++ habits
Inn <c-up> <c-y>
Inn <c-down> <c-e>
Inn <silent> <c-s-up> :m-2<cr>
Inn <silent> <c-s-down> :m+1<cr>
Inn <silent> <c-s-PageUp> :tabm -1<cr>
Inn <silent> <c-s-PageDown> :tabm +1<cr>
" hide search highlighting
Inn <silent> <c-]> :nohls<enter>
" rebind annoying things
" reflow text
nn Q gq
vn Q gq
" split lines (opposite of J)
nn K i<cr><esc>k$
vn K <nop>
" follow tag
nn <bar> <c-]>
" delete line
"nn D dd
" this frees up x and X for use if you like
set <s-Del>=[3;2~
Inn <s-Del> X
" unfollow your leaders
let leader="\\"
" no-op
nn <Leader><Leader> :<cr>
"ino <c-\> <C-o><Leader> " this doesn't workkkkkkkkk
nm <Leader>i i?<Esc>r
nm <Leader>a a?<Esc>r
nn <Leader>p "0p
nn <Leader>P "0P
nn <Leader>e :e **/*
nn <Leader>b :ls<cr>:b<space>
nn <Leader><F10> :call SaveSession()<cr>:xall<cr>
nn <silent> <Leader>d :cd %:p:h<cr>:pwd<cr>
nn <Leader>. @:
"nn <Leader>? :exec getline(".")
nn <Leader>, :Tab /,\zs<cr>
"nn <Leader>x :system('chmod +x %') | e
" trying some copypasta from http://stackoverflow.com/a/16084326
set path=.,**
nn <Leader>f :find *
nn <Leader>F :find <c-r>=expand('%:h').'/*'<cr>
" extension binds {{{1
map <silent> <c-n> :CtrlPBuffer<cr>
" messing around with colors
" a la https://github.com/xolox/vim-colorscheme-switcher/blob/master/autoload/xolox/colorscheme_switcher.vim
fu! HiDump()
redir => out
silent hi
redir END
let @a = out
put a
endf
nn <Leader>s :call SyntaxAttr()<cr>
nn <Leader>1 :colo property2<cr>
nn <Leader>2 :colo clearance-dyn<cr>
nn <Leader>3 :colo Tomorrow-Night<cr>
nn <Leader>4 :colo jellybeans<cr>
nn <Leader>5 :colo colorsbox-stnight<cr>
nn <Leader>6 :colo redblack<cr>
nn <Leader>7 :colo property16<cr>
nn <Leader>h :tabe<cr>:call HiDump()<cr>
" helper function to toggle hex mode
" http://vim.wikia.com/wiki/Improved_hex_editing
fu! ToggleHex()
" hex mode should be considered a read-only operation
" save values for modified and read-only for restoration later,
" and clear the read-only flag for now
let l:modified=&mod
let l:oldreadonly=&readonly
let &readonly=0
let l:oldmodifiable=&modifiable
let &modifiable=1
if !exists("b:editHex") || !b:editHex
" save old options
let b:oldft=&ft
let b:oldbin=&bin
" set new options
setlocal binary " make sure it overrides any textwidth, etc.
silent :e " this will reload the file without trickeries
"(DOS line endings will be shown entirely )
let &ft="xxd"
" set status
let b:editHex=1
" switch to hex editor
%!xxd
else
" restore old options
let &ft=b:oldft
if !b:oldbin
setlocal nobinary
endif
" set status
let b:editHex=0
" return to normal editing
%!xxd -r
endif
" restore values for modified and read only state
let &mod=l:modified
let &readonly=l:oldreadonly
let &modifiable=l:oldmodifiable
endf
nn <F2> :call ToggleHex()<cr>
"%s# \(\*\|\*\*\|/\|//\) #\1#g
" misc {{{1
set list listchars=tab:»·,trail,extends:…,nbsp:‗
" including this in case i'm on a _really_ bad terminal:
"set list listchars=tab:>-,trail:.,extends:>,nbsp:_
try | execute pathogen#infect() | catch /E117/ | endtry
set background=dark
try
colorscheme property16
catch /E185/
colorscheme desert
endtry
" set up default windows on a big terminal
fu! DefaultWin()
if &columns >= 84*2 && &lines >= 36*2
"/vim\
"| |_|
"|.| |
"\---/
vsplit
wincmd l
split
wincmd h
endif
endf
augroup DefaultWin
au!
au VimEnter * call DefaultWin()
augroup END
" airline {{{1
if has('gui_running')
" airline is broken in gvim (for me) for now
else
"if exists('g:airline_symbols')
set laststatus=2
let g:airline#extensions#tabline#enabled = 0
endif
let g:airline_mode_map = {
\ 'c': 'COM',
\ 'i': 'INS',
\ 'n': '·ω·',
\ 'R': 'REP',
\ 'S': 'S-L',
\ 's': 'SEL',
\ 't': 'CON',
\ 'V': 'V-L',
\ 'v': 'VIS',
\ '': 'S-B',
\ '': 'V-B',
\ '__': '———',
\ }
let g:airline_symbols = {
\ 'branch': '',
\ 'crypt': '',
\ 'linenr': '',
\ 'modified': '+',
\ 'paste': 'ρ',
\ 'readonly': 'R',
\ 'space': ' ',
\ 'whitespace': '·',
\ }
let g:airline_left_sep = ''
let g:airline_right_sep = ''
let g:airline#extensions#default#section_truncate_width = {
\ 'b': 79,
\ 'x': 60,
\ 'y': 84,
\ 'z': 45,
\ }
let g:airline#extensions#tabline#show_tab_nr = 0
let g:airline#extensions#tabline#show_tab_type = 0
let g:airline#extensions#tabline#fnametruncate = 20
let g:airline#extensions#tabline#fnamemod = ':t'
let g:airline#extensions#tabline#formatter = 'unique_tail_improved'
let g:airline#extensions#tabline#show_close_button = 0
let g:airline#extensions#tabline#buffer_nr_show = 0
let g:airline#extensions#tabline#buffer_nr_format = '%s ┊'
"  
let g:airline#extensions#tabline#left_sep = '┊'
let g:airline#extensions#tabline#left_alt_sep = '┊'
let g:airline#extensions#tabline#right_sep = '┊'
let g:airline#extensions#tabline#right_alt_sep = '┊'
"let g:airline#extensions#whitespace#mixed_indent_algo = 2
let g:airline#extensions#whitespace#symbol = '‗'
let g:airline#extensions#whitespace#trailing_format = '· %s'
let g:airline#extensions#whitespace#long_format = '… %s'
let g:airline#extensions#whitespace#mixed_indent_format = '‼ %s'