diff options
Diffstat (limited to 'vim/.vim/plugin')
-rw-r--r-- | vim/.vim/plugin/dircreate.vim | 31 | ||||
-rw-r--r-- | vim/.vim/plugin/eolws.vim | 6 | ||||
-rw-r--r-- | vim/.vim/plugin/keywordprg.vim | 33 | ||||
-rw-r--r-- | vim/.vim/plugin/opinionated-defaults.vim | 157 | ||||
-rw-r--r-- | vim/.vim/plugin/rainbow_paren.vim | 96 |
5 files changed, 323 insertions, 0 deletions
diff --git a/vim/.vim/plugin/dircreate.vim b/vim/.vim/plugin/dircreate.vim new file mode 100644 index 0000000..11da7f9 --- /dev/null +++ b/vim/.vim/plugin/dircreate.vim @@ -0,0 +1,31 @@ +function! s:ensure_dir_exists() + let l:required_dir = expand("%:h") + if !isdirectory(l:required_dir) + if <SID>ask_quit("Directory '" . l:required_dir . "' doesn't exist.", "&Create it?") + return + endif + + try + call mkdir(l:required_dir, 'p') + catch + call <SID>ask_quit("Can't create '" . l:required_dir . "'", "&Continue anyway?") + endtry + endif +endfunction + +function! s:ask_quit(msg, proposed_action) + if confirm(a:msg, "&Quit?\n" . a:proposed_action) == 1 + if len(getbufinfo()) > 1 + silent bd + return 1 + else + exit + end + endif + return 0 +endfunction + +augroup dircreate + autocmd! + autocmd BufNewFile * call <SID>ensure_dir_exists() +augroup END diff --git a/vim/.vim/plugin/eolws.vim b/vim/.vim/plugin/eolws.vim new file mode 100644 index 0000000..1f1a003 --- /dev/null +++ b/vim/.vim/plugin/eolws.vim @@ -0,0 +1,6 @@ +augroup eolws + autocmd! + autocmd InsertEnter * syn clear EOLWS | syn match EOLWS excludenl /\s\+\%#\@!$/ + autocmd InsertLeave * syn clear EOLWS | syn match EOLWS excludenl /\s\+$/ +augroup END +highlight EOLWS ctermbg=red guibg=red diff --git a/vim/.vim/plugin/keywordprg.vim b/vim/.vim/plugin/keywordprg.vim new file mode 100644 index 0000000..dfedd80 --- /dev/null +++ b/vim/.vim/plugin/keywordprg.vim @@ -0,0 +1,33 @@ +function! Help(visual, iskeyword, command) + let l:iskeyword = &iskeyword + for l:kw in a:iskeyword + exe 'set iskeyword+=' . l:kw + endfor + if a:visual + let l:oldreg = @a + normal! gv"aygv + let l:word = @a + let @a = l:oldreg + else + let l:word = expand('<cword>') + endif + let &iskeyword = l:iskeyword + + exe 'noswapfile ' . &helpheight . 'new ' . l:word + setlocal buftype=nofile + setlocal bufhidden=wipe + setlocal nobuflisted + + setlocal modifiable + exe 'call ' . a:command . '("' . l:word . '")' + normal! ggdd + setlocal nomodifiable +endfunction + +function! s:man(word) + exe 'silent read! man -Pcat ' . a:word + setlocal filetype=man +endfunction + +nnoremap <silent>K :call Help(0, [], '<SID>man')<CR> +xnoremap <silent>K :call Help(1, [], '<SID>man')<CR> diff --git a/vim/.vim/plugin/opinionated-defaults.vim b/vim/.vim/plugin/opinionated-defaults.vim new file mode 100644 index 0000000..6ce034b --- /dev/null +++ b/vim/.vim/plugin/opinionated-defaults.vim @@ -0,0 +1,157 @@ +""" GENERAL """ +set nocompatible +syntax on +filetype indent plugin on +augroup opinionated_defaults + autocmd! +augroup END + + +""" PERSISTENCE """ + +" remember as many history items as possible (command, search, etc) +set history=10000 +" enable persistent undo (undo even after closing and reopening vim) +if has('persistent_undo') + let s:undocachedir = $HOME . '/.cache/vim/undo' + if !isdirectory(s:undocachedir) + call mkdir(s:undocachedir, 'p') + endif + exe "set undodir=" . s:undocachedir + set undofile +endif +" use a separate swapfile directory +let s:swapfiledir = $HOME . '/.cache/vim/swap' +if !isdirectory(s:swapfiledir) + call mkdir(s:swapfiledir, 'p') +endif +exe "set directory=" . s:swapfiledir . "//" +" use a separate view directory +let s:viewdir = $HOME . '/.cache/vim/view' +if !isdirectory(s:viewdir) + call mkdir(s:viewdir, 'p') +endif +exe "set viewdir=" . s:viewdir + + +""" BUFFERS """ + +" automatically write the buffer before :make, shell commands, etc +set autowrite +" ask to save modified buffers when quitting, instead of throwing an error +set confirm +" allow switching to other buffers when the current one is modified +set hidden +" these two restore the last known cursor position when a buffer is loaded +set nostartofline +autocmd opinionated_defaults BufReadPost * + \ if line("'\"") <= line('$') | + \ exe 'normal! g`"' | + \ endif + + +""" DISPLAY """ + +" show as much of a line as possible if it doesn't all fit on the screen +set display+=truncate +" more useful display of nonprinting characters (<07> instead of ^G) +set display+=uhex +" don't redraw in the middle of noninteractive commands (maps, macros, etc) +set lazyredraw +" always give a message for the number of lines delete/changed +set report=0 +" keep some additional context visible when scrolling +set scrolloff=5 +if has('cmdline_info') + " display the current partial command and size of the visual selection + set showcmd +endif +if has('conceal') + " enable syntax-specific hiding of text + set conceallevel=2 +endif +if has('linebreak') + " display a marker when a line was wrapped + set showbreak=> +endif + + +""" EDITING """ + +" automatically use an indent that matches the previous line +set autoindent +" allow backspacing over everything +set backspace=indent,eol,start +" remove leading comment characters intelligently when joining lines +set formatoptions+=j +" always join with a single space, even between sentences +set nojoinspaces +" try to always keep indentation lined up on shiftwidth boundaries +set shiftround +" keep softtabstop and shiftwidth in sync +set softtabstop=-1 + + +""" COMMAND MODE """ + +" make command mode completion work more like the shell: +" first, complete the longest common sequence, +" then show a list, +" then cycle through completing the full names in the list in order +set wildmode=longest,list,full +if exists('+wildignorecase') + " make command mode completion case insensitive + set wildignorecase +endif + + +""" SEARCH """ + +" make searches case-insensitive +set ignorecase +" unless they include a capital letter +set smartcase +if has('extra_search') + " highlight all matches when searching + set hlsearch +endif + + +""" TERMINAL STUFF """ + +" wait a much shorter amount of time for escape sequences +" (this makes <Esc> much more responsive) +set ttimeoutlen=50 +" send text to the terminal in such a way that line wrapping is done at the +" terminal level, so copying and pasting wrapped lines works correctly +" (assuming you temporarily unset showbreak) +set ttyfast +" entirely disable error bells: +" make all bells visual bells +set visualbell +" and then disable visual bells +set t_vb= + + +""" COLORS """ + +" force vim to use 256 colors +" (it typically can't detect this while in screen/tmux since TERM=screen +" doesn't advertise it, even though ~everything does support it these days) +set t_Co=256 +" globally highlight diff conflict markers +match ErrorMsg '^\(<\||\|=\|>\)\{7\}\([^=].\+\)\?$' + + +""" MAPPINGS """ + +" keep the current selection when indenting +xnoremap < <gv +xnoremap > >gv +" make Y behave analogously to D instead of dd +nnoremap Y y$ +" make arrow keys move visually (since j/k already move linewise) +noremap <up> gk +noremap <down> gj +inoremap <up> <C-o>gk +inoremap <down> <C-o>gj diff --git a/vim/.vim/plugin/rainbow_paren.vim b/vim/.vim/plugin/rainbow_paren.vim new file mode 100644 index 0000000..9c26134 --- /dev/null +++ b/vim/.vim/plugin/rainbow_paren.vim @@ -0,0 +1,96 @@ +" this script by Shawn M Moore aka Sartak <sartak at gmail.com> +" also by Michael R Geddes aka frogonwheels <vimmer at frog.wheelycreek.net> +" originally by anonymous + +" this in the public domain +" last updated 25 Mar 07 + +" this does nothing unless you, +" let g:rainbow = 1 + +" and set which kinds of character pairs you want to rainbow +" let g:rainbow_paren = 1 " () +" let g:rainbow_brace = 1 " {} +" let g:rainbow_bracket = 1 " [] +" let g:rainbow_angle = 1 " <> + +" if you want the different types to nest, such that the braces in ({}) are +" colored the same as the internal parens of (()), then +" let g:rainbow_nested = 1 + +function! Rainbow() + let s:basename = 'level' + exe 'hi '.s:basename.'1c ctermfg=6 guifg=#1673b0' + exe 'hi '.s:basename.'2c ctermfg=2 guifg=#008551' + exe 'hi '.s:basename.'3c ctermfg=3 guifg=#b25200' + exe 'hi '.s:basename.'4c ctermfg=4 guifg=#4369cc' + exe 'hi '.s:basename.'5c ctermfg=5 guifg=#a045a7' + " this color is never nested, it only appears on the outermost layer + exe 'hi '.s:basename.'6c ctermfg=1 guifg=#c7394e' + + " helper function + func s:DoSyn(cur, top, left, right, uniq) + let uniq = a:uniq + if exists("g:rainbow_nested") && g:rainbow_nested != 0 + let uniq = "" + endif + + let cmd = 'syn region '.s:basename.uniq.a:cur.' transparent fold matchgroup='.s:basename.a:cur.'c start=/'.a:left.'/ end=/'.a:right.'/ contains=TOP' + + let i = a:cur + + if i == 1 + let i = a:top + endif + + while i <= a:top + let cmd = cmd . ',' . s:basename . uniq . i + let i = i + 1 + endwhile + exe cmd + endfunc + + func s:DoSyntaxes(count) + let i = 1 + + while i <= a:count + " if you define new pairs, make sure to take into account that the + " delimiter is currently / and that it uses regex, so you need to escape + " regex metachars (like what is done for brackets) + + if exists("g:rainbow_paren") && g:rainbow_paren != 0 + " ocaml uses (* *) for comments; these shouldn't be highlighted + if &filetype == "ocaml" + call s:DoSyn(i, a:count, "(\\*\\@!", "\\*\\@<!)", "a") + else + call s:DoSyn(i, a:count, "(", ")", "a") + endif + endif + + if exists("g:rainbow_brace") && g:rainbow_brace != 0 + call s:DoSyn(i, a:count, "{", "}", "b") + endif + + if exists("g:rainbow_bracket") && g:rainbow_bracket != 0 + call s:DoSyn(i, a:count, "\\[", "\\]", "c") + endif + + if exists("g:rainbow_angle") && g:rainbow_angle != 0 + call s:DoSyn(i, a:count, "<", ">", "d") + endif + + let i = i + 1 + endwhile + endfun + + call s:DoSyntaxes(6) " 6 is the number of colors we have + + delfun s:DoSyn + delfun s:DoSyntaxes +endfunction + +if exists("g:rainbow") && g:rainbow + augroup rainbow + autocmd BufWinEnter,FileType * call Rainbow() + augroup END +endif |