# HG changeset patch # User zegervdv # Date 1421833229 -3600 # Node ID 55ff9bb3ea2291b1cbe1b0cd9cda9fd2a0b12e37 # Parent 1d9bec72b9b3740cdacc4cc447db3c14ea8f3720 Clean up vimrc diff -r 1d9bec72b9b3 -r 55ff9bb3ea22 vim/autoload/plug.vim --- a/vim/autoload/plug.vim Wed Jan 21 09:11:59 2015 +0100 +++ b/vim/autoload/plug.vim Wed Jan 21 10:40:29 2015 +0100 @@ -73,7 +73,7 @@ let s:plug_buf = get(s:, 'plug_buf', -1) let s:mac_gui = has('gui_macvim') && has('gui_running') let s:is_win = has('win32') || has('win64') -let s:nvim = exists('##JobActivity') && !s:is_win +let s:nvim = has('nvim') && !s:is_win let s:me = resolve(expand(':p')) let s:base_spec = { 'branch': 'master', 'frozen': 0 } let s:TYPE = { @@ -136,6 +136,10 @@ endfor endfunction +function! s:assoc(dict, key, val) + let a:dict[a:key] = add(get(a:dict, a:key, []), a:val) +endfunction + function! plug#end() if !exists('g:plugs') return s:err('Call plug#begin() first') @@ -147,7 +151,7 @@ augroup END augroup! PlugLOD endif - let lod = {} + let lod = { 'ft': {}, 'map': {}, 'cmd': {} } filetype off for name in g:plugs_order @@ -162,19 +166,12 @@ for cmd in s:to_a(plug.on) if cmd =~ '^.\+' if empty(mapcheck(cmd)) && empty(mapcheck(cmd, 'i')) - for [mode, map_prefix, key_prefix] in - \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] - execute printf( - \ '%snoremap %s %s:call lod_map(%s, %s, "%s")', - \ mode, cmd, map_prefix, string(cmd), string(name), key_prefix) - endfor + call s:assoc(lod.map, cmd, name) endif call add(s:triggers[name].map, cmd) elseif cmd =~ '^[A-Z]' if exists(':'.cmd) != 2 - execute printf( - \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "", , , , %s)', - \ cmd, string(cmd), string(name)) + call s:assoc(lod.cmd, cmd, name) endif call add(s:triggers[name].cmd, cmd) endif @@ -186,19 +183,31 @@ if !empty(types) call s:source(s:rtp(plug), 'ftdetect/**/*.vim', 'after/ftdetect/**/*.vim') endif - for key in types - if !has_key(lod, key) - let lod[key] = [] - endif - call add(lod[key], name) + for type in types + call s:assoc(lod.ft, type, name) endfor endif endfor - for [key, names] in items(lod) + for [cmd, names] in items(lod.cmd) + execute printf( + \ 'command! -nargs=* -range -bang %s call s:lod_cmd(%s, "", , , , %s)', + \ cmd, string(cmd), string(names)) + endfor + + for [map, names] in items(lod.map) + for [mode, map_prefix, key_prefix] in + \ [['i', '', ''], ['n', '', ''], ['v', '', 'gv'], ['o', '', '']] + execute printf( + \ '%snoremap %s %s:call lod_map(%s, %s, "%s")', + \ mode, map, map_prefix, string(map), string(names), key_prefix) + endfor + endfor + + for [ft, names] in items(lod.ft) augroup PlugLOD execute printf('autocmd FileType %s call lod_ft(%s, %s)', - \ key, string(key), string(names)) + \ ft, string(ft), string(names)) augroup END endfor @@ -336,11 +345,11 @@ return endif for cmd in s:triggers[a:name].cmd - execute 'delc' cmd + execute 'silent! delc' cmd endfor for map in s:triggers[a:name].map - execute 'unmap' map - execute 'iunmap' map + execute 'silent! unmap' map + execute 'silent! iunmap' map endfor call remove(s:triggers, a:name) endfunction @@ -367,13 +376,13 @@ doautocmd filetypeindent FileType endfunction -function! s:lod_cmd(cmd, bang, l1, l2, args, name) - call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) +function! s:lod_cmd(cmd, bang, l1, l2, args, names) + call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) execute printf('%s%s%s %s', (a:l1 == a:l2 ? '' : (a:l1.','.a:l2)), a:cmd, a:bang, a:args) endfunction -function! s:lod_map(map, name, prefix) - call s:lod([a:name], ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) +function! s:lod_map(map, names, prefix) + call s:lod(a:names, ['ftdetect', 'after/ftdetect', 'plugin', 'after/plugin']) let extra = '' while 1 let c = getchar(0) diff -r 1d9bec72b9b3 -r 55ff9bb3ea22 vimrc --- a/vimrc Wed Jan 21 09:11:59 2015 +0100 +++ b/vimrc Wed Jan 21 10:40:29 2015 +0100 @@ -4,41 +4,52 @@ call plug#begin('~/.vim/plugged') " General Plugins Plug 'tpope/vim-sensible' +Plug 'tpope/vim-fugitive' +Plug 'tpope/vim-repeat' + +" Spelling Plug 'tpope/vim-abolish' -Plug 'tpope/vim-fugitive' -Plug 'godlygeek/tabular', { 'on' : 'Tabularize' } -Plug 'tpope/vim-endwise' + +" Brackets Plug 'tpope/vim-surround' Plug 'jiangmiao/auto-pairs' -Plug 'kshenoy/vim-signature' -Plug 'tpope/vim-repeat' -Plug 't9md/vim-smalls' -Plug 'xolox/vim-session' -Plug 'tpope/vim-eunuch', { 'on' : ['Remove', 'Unlink', 'Move', 'Rename', 'Mkdir', 'Chmod', 'Find', 'Locate', 'SudoEdit', 'SudoWrite']} -Plug 'scrooloose/syntastic' + +" Formatting +Plug 'godlygeek/tabular', { 'on' : 'Tabularize' } + +" Comments Plug 'tpope/vim-commentary' + +" Moving in files Plug 'wellle/targets.vim' -Plug 'mtth/scratch.vim' -Plug 'mrmargolis/dogmatic.vim' -Plug 'whatyouhide/vim-gotham' + +" Command line +Plug 'tpope/vim-eunuch', { 'on' : ['Remove', 'Unlink', 'Move', 'Rename', 'Mkdir', 'Chmod', 'Find', 'Locate', 'SudoEdit', 'SudoWrite']} -" Undo +" Syntax and checking +Plug 'scrooloose/syntastic' + +" Undoing Plug 'sjl/gundo.vim', { 'on': 'GundoToggle' } " Tmux Plug 'christoomey/vim-tmux-navigator' Plug 'tpope/vim-dispatch' -" Search and Complete -" Plug 'Shougo/neocomplete' +" Completing and snippets Plug 'ajh17/VimCompletesMe' -Plug 'Shougo/neosnippet' -Plug 'Shougo/neosnippet-snippets' -Plug 'Shougo/vimproc', { 'do': 'make' } -Plug 'Shougo/unite.vim' -Plug 'Shougo/vimfiler.vim' -Plug 'Shougo/unite-outline' -Plug 'tsukkee/unite-tag' + +" Vim file navigation +Plug 'tpope/vim-vinegar' + +" Open and find files +Plug 'ctrlpvim/ctrlp.vim' + +" Don't use arrows! +Plug 'mrmargolis/dogmatic.vim' + +" Theme +Plug 'whatyouhide/vim-gotham' " Ruby Plug 'tpope/vim-rails', { 'for': 'ruby' } @@ -61,18 +72,12 @@ " Git Plug 'tpope/vim-git' - -" Dependencies -Plug 'MarcWeber/vim-addon-mw-utils' -Plug 'tomtom/tlib_vim' -Plug 'xolox/vim-misc' - - call plug#end() " }}} -" General Settings {{{ + +" General Settings and options {{{ set nocompatible - +" Backspace over everything, like normal set backspace=2 set autowrite @@ -96,15 +101,12 @@ set lbr set tabstop=2 shiftwidth=2 -" Layout +" Theme and style set t_Co=256 set background=dark color gotham set guifont=Inconsolata\ for\ Powerline:h12 -" Make background color same as terminal ("transparent") -" hi Normal ctermbg=none -set autowrite set hidden set hlsearch set incsearch @@ -170,11 +172,7 @@ " Sentences are ended with double spaces set cpo+=J - - -" set list -" set listchars=tab:▸\ ,eol:¬ -" }}} +" }}} " Status line {{{ function! Status() let statusline = '' @@ -189,51 +187,17 @@ set laststatus=2 set statusline=%!Status() " }}} -" Custom remaps and tricks {{{ -" Enable spelling only for latex and text -au BufNewFile,BufRead,BufEnter *.tex setlocal spell spelllang=en_gb -au BufNewFile,BufRead,BufEnter *.tex setlocal textwidth=0 -au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb -au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 -au FileType gitcommit setlocal spell spelllang=en_gb -set thesaurus+=~/.vim/thesaurus/mthesaur.txt -autocmd BufRead *_spec.rb set filetype=rspec - -" Fix comments for matlab -autocmd FileType matlab setlocal commentstring=\%\ %s - -highlight SpellBad ctermbg=256 ctermfg=210 -highlight SpellLocal ctermbg=240 ctermfg=010 -highlight SpellCap ctermbg=256 ctermfg=211 - -" When editing a file, always jump to the last known cursor position. -" Don't do it for commit messages, when the position is invalid, or when -" inside an event handler (happens when dropping a file on gvim). -autocmd BufReadPost * - \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | - \ exe "normal g`\"" | - \ endif - -" Set leader to space -" let mapleader = " " +" Mappings {{{ +" Set leader to spacebar map -" Fix weird error where space n hangs vim with search -noremap n - " See long lines as line breaks map j gj map k gk -" remap tag-search to better place -" nmap -function! JumpToTagInSplit() - execute "normal! \v\mzzMzvzz15\" - execute "keepjumps normal! `z" - Pulse -endfunction -nnoremap :silent! call JumpToTagInSplit() +" Remap tag-search to better place +nmap " Jump to end of line in insert mode inoremap I @@ -251,9 +215,6 @@ " Switch between the last two files nnoremap -" Move between buffers -nnoremap gb :bnext -nnoremap gB :bprevious " Very Magic search patterns nmap / /\v @@ -268,49 +229,9 @@ inoremap £ \ -nnoremap % -vnoremap % - -" Move between splits -" map j -" map k -" map l -" map h - -" highlight last inserted text +" Highlight last inserted text nnoremap gV `[v`] -" Briefly change colour of last highlight -" nnoremap n n:call HLNext(0.4) -" nnoremap N N:call HLNext(0.4) - -function! HLNext (blinktime) - highlight WhiteOnRed ctermfg=white ctermbg=red guifg=white guibg=red - let [bufnum, lnum, col, off] = getpos('.') - let matchlen = strlen(matchstr(strpart(getline('.'),col-1),@/)) - let target_pat = '\c\%#'.@/ - let ring = matchadd('WhiteOnRed', target_pat, 101) - redraw - exec 'sleep ' . float2nr(a:blinktime * 1000) . 'm' - call matchdelete(ring) - redraw -endfunction - -" This is adapted from -" http://vim.wikia.com/wiki/Windo_and_restore_current_window -function! KeepWin(command) - let currwin=winnr() - execute a:command - execute currwin . 'wincmd w' -endfunction - -augroup insertMatch - au! - au VimEnter * NoMatchParen - au InsertEnter * call KeepWin("DoMatchParen") - au InsertLeave * call KeepWin("NoMatchParen") -augroup END - " Highlight VCS conflict markers match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$' @@ -337,27 +258,44 @@ endif endfunction -au FileType c setl foldmethod=syntax - -au VimResized * exe "normal! \=" - +" Some emacs behavior cnoremap cnoremap " Swap backticks and quotes nnoremap ` ' nnoremap ' ` +" }}} -" Note that this will overwrite the contents of the z mark. I never use it, but -" if you do you'll probably want to use another mark. -inoremap mzgUiw`za +" Functions {{{ +" When editing a file, always jump to the last known cursor position. +" Don't do it for commit messages, when the position is invalid, or when +" inside an event handler (happens when dropping a file on gvim). +autocmd BufReadPost * + \ if &ft != 'gitcommit' && line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal g`\"" | + \ endif -nnoremap ev :split $MYVIMRC +" Make matching parenthesis more clear +" This is adapted from +" http://vim.wikia.com/wiki/Windo_and_restore_current_window +function! KeepWin(command) + let currwin=winnr() + execute a:command + execute currwin . 'wincmd w' +endfunction -" Move lines from visual selection -vnoremap :m '>+1gv=gv -vnoremap :m '<-2gv=gv +augroup insertMatch + au! + au VimEnter * NoMatchParen + au InsertEnter * call KeepWin("DoMatchParen") + au InsertLeave * call KeepWin("NoMatchParen") +augroup END +" Resize splits after window resize +au VimResized * exe "normal! \=" + +" Custom folding by Steve Losh function! MyFoldText() " {{{ let line = getline(v:foldstart) @@ -374,125 +312,42 @@ return line . '…' . repeat(" ",fillcharcount) . foldedlinecount . '…' . ' ' endfunction " }}} set foldtext=MyFoldText() +" }}} -" VHDL ctags -let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures' -" }}} +" Filetype specific settings " Latex {{{ " Open pdf nnoremap v :!open -a /Applications/TeX/TeXShop.app %:r.pdf " Set compiler to rubber autocmd FileType tex setlocal makeprg=latexmk\ -pdf\ %:r -" }}} -" Unite {{{ -call unite#filters#matcher_default#use(['matcher_fuzzy']) -call unite#filters#sorter_default#use(['sorter_rank']) -" call unite#set_profile('files', 'smartcase', 1) -call unite#custom#profile('files', 'context.smartcase', 1) -call unite#custom#source('line,outline', 'matchers', 'matcher_fuzzy') -call unite#custom#source( 'buffer', 'converters', ['converter_file_directory']) -" sort file results by length -call unite#custom#source('file', 'sorters', 'sorter_length') -call unite#custom#source('file_rec/async', 'converters', []) -call unite#custom#source('file_rec/async', 'sorters', []) -call unite#custom#source('file_rec/async', 'ignore_globs', split(&wildignore, ',')) -call unite#custom#source('file_rec/async', 'max_candidates', 50) -let g:unite_enable_start_insert=0 -let g:unite_source_history_yank_enable=1 -let g:unite_source_rec_max_cache_files=3000 -let g:unite_prompt='» ' -if executable('ag') - let g:unite_source_grep_command = 'ag' - let g:unite_source_grep_default_opts = - \ '-i --line-numbers --nocolor --nogroup --hidden --ignore ' . - \ '''.hg'' --ignore ''.svn'' --ignore ''.git'' --ignore ''.bzr''' - let g:unite_source_grep_recursive_opt = '' - let g:unite_source_rec_async_command = 'ag --nocolor --nogroup --hidden -g ""' -elseif executable('ack') - let g:unite_source_grep_command='ack' - let g:unite_source_grep_default_opts='--no-heading --no-color -C4' - let g:unite_source_grep_recursive_opt='' -endif -function! s:unite_settings() - nmap Q (unite_exit) - nmap (unite_exit) - imap (unite_select_next_line) - imap (unite_select_previous_line) -endfunction -autocmd FileType unite call s:unite_settings() - -nnoremap k :Unite -auto-preview -buffer-name=recent file_mru -nnoremap y :Unite -buffer-name=yanks history/yank -nnoremap f :Unite -no-quit -buffer-name=search grep:. -nnoremap g :Unite -no-quit -buffer-name=search grep:. -nnoremap o :Unite outline -nnoremap t :Unite tag -nnoremap :Unite -start-insert buffer file_rec/async -" nnoremap h :Unite ssh://Hurricane/STM-Quadcopter/source -" nnoremap i :Unite ssh://imac-van-zeger.local/Documents -" }}} -" Unite Build {{{ -" TODO: Create builders eg Latex, Vagrant? -" }}} -" Vimfiler {{{ -" Use vimfiler as default -let g:vimfiler_as_default_explorer = 1 -nnoremap e :VimFilerExplorer -let g:vimfiler_ignore_pattern = '\%(.o\|.bin\|.elf\|.un\~\|.swp\)$' -" }}} -" Cucumber {{{ -" map f :call RunAllFeatures() -" map k :call RunCurrentFeature() +au BufNewFile,BufRead,BufEnter *.tex setlocal spell spelllang=en_gb +au BufNewFile,BufRead,BufEnter *.tex setlocal textwidth=0 " }}} " Markdown {{{ let g:vim_markdown_folding_disabled=1 " }}} -" Neo Complete {{{ -let g:neocomplete#enable_at_startup = 1 -let g:neocomplete#enable_smart_case = 1 -let g:neocomplete#force_overwrite_completefunc = 1 -let g:marching_enable_neocomplete = 1 -let g:neocomplete#enable_fuzzy_completion = 1 +" Text {{{ +au BufNewFile,BufRead,BufEnter *.txt setlocal spell spelllang=en_gb +au BufNewFile,BufRead,BufEnter *.txt setlocal textwidth=0 +" }}} +" Git commit messages {{{ +au FileType gitcommit setlocal spell spelllang=en_gb +" }}} +" Ruby {{{ +autocmd BufRead *_spec.rb set filetype=rspec +" }}} +" Matlab {{{ +autocmd FileType matlab setlocal commentstring=\%\ %s +" }}} +" C {{{ +au FileType c setlocal foldmethod=syntax +" }}} +" VHDL {{{ +" VHDL ctags +let g:tlist_vhdl_settings = 'vhdl;d:package declarations;b:package bodies;e:entities;a:architecture specifications;t:type declarations;p:processes;f:functions;r:procedures' +" }}} -inoremap pumvisible() ? neocomplete#smart_close_popup()"\" : "\" -inoremap neocomplete#undo_completion() -inoremap neocomplete#complete_common_string() -function! CleverCr() - if pumvisible() - if neosnippet#expandable() - let exp = "\(neosnippet_expand)" - return exp . neocomplete#smart_close_popup() - else - return neocomplete#smart_close_popup() - endif - else - return "\" - endif -endfunction -" close popup and save indent or expand snippet -imap CleverCr() - -" }}} -" Neo Snippets {{{ -imap (neosnippet_expand_or_jump) -smap (neosnippet_expand_or_jump) -xmap (neosnippet_expand_target) - -" imap neosnippet#expandable_or_jumpable() ? -" \ "\(neosnippet_expand_or_jump)" -" \: pumvisible() ? "\" : "\" -" smap neosnippet#expandable_or_jumpable() ? -" \ "\(neosnippet_expand_or_jump)" -" \: "\" - - -imap neosnippet#expandable() == 1 ? "\(neosnippet_expand_or_jump)" : pumvisible() ? "\" : "\" -imap neosnippet#expandable_or_jumpable() == 1 ? "\(neosnippet_expand_or_jump)" : pumvisible() ? "\" : "\" -smap neosnippet#expandable() == 1 ? "\(neosnippet_expand_or_jump)" : pumvisible() ? "\" : "\" -" let g:neocomplete#sources#omni#input_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::' - -let g:neosnippet#snippets_directory='~/.vim/snippets' -" }}} +" Plugin settings " Tabular {{{ inoremap :call align()a @@ -519,9 +374,6 @@ nmap a, :Tabularize /,\zs/l0l1 vmap a, :Tabularize /,\zs/l0l1 vmap a- :Tabularize /- -" }}} -" Tagbar {{{ -nmap :TagbarToggle " }}} " Syntastic {{{ let g:syntastic_check_on_open=1 @@ -529,32 +381,19 @@ " Gundo tree {{{ nnoremap u :GundoToggle " }}} -" Smalls {{{ -nmap (smalls) -omap (smalls) -xmap (smalls) -" }}} -" Textmanip {{{ -xmap (textmanip-move-down) -xmap (textmanip-move-up) -xmap (textmanip-move-left) -xmap (textmanip-move-right) -xmap (textmanip-toggle-mode) -" }}} -" Startify {{{ -let g:startify_session_dir = "~/.vim/sessions" -" }}} -" Vimwiki {{{ -let g:notes_directories = ['~/.vim/notes'] -" }}} -" Vim Sessions {{{ -let g:session_autosave = 'no' -" }}} " Dispatch {{{ nnoremap s :Make autocmd FileType python setlocal makeprg=ipython\ --pdb\ % autocmd FileType ruby setlocal makeprg=ruby\ % " }}} +" CtrlP {{{ +if executable('ag') + set grepprg=ag\ --nogroup\ --color + + let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""' + let g:ctrlp_use_caching = 0 +endif +" }}} " Load local vimrc if filereadable($HOME . "/.vimrc.local")