comparison vim/vimrc @ 426:67f14a8c2304

Improve Vim configuration.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 28 Mar 2018 20:07:30 -0700
parents d8086f81b9c8
children 71a080d4d83c
comparison
equal deleted inserted replaced
425:350f7a55ff33 426:67f14a8c2304
21 21
22 " Get the platform we're running on. 22 " Get the platform we're running on.
23 if has("win32") || has("win64") || has("dos32") 23 if has("win32") || has("win64") || has("dos32")
24 let s:vim_platform = "windows" 24 let s:vim_platform = "windows"
25 let s:path_sep = "\\" 25 let s:path_sep = "\\"
26 elseif has("mac")
27 let s:vim_platform = "mac"
28 let s:path_sep = '/'
26 else 29 else
27 let s:vim_platform = "unix" 30 let s:vim_platform = "unix"
28 let s:path_sep = '/' 31 let s:path_sep = '/'
29 endif 32 endif
30 33
65 au GUIEnter * simalt ~x 68 au GUIEnter * simalt ~x
66 endif 69 endif
67 endif 70 endif
68 71
69 function! s:HasPlugin(plugname) abort 72 function! s:HasPlugin(plugname) abort
70 return globpath(&runtimepath, 'plugin/'.a:plugname.'.vim') !=# '' 73 return globpath(&runtimepath, 'plugin/'.a:plugname.'.vim') !=# ''
71 endfunction 74 endfunction
72 75
73 " }}} 76 " }}}
74 77
75 " General Settings {{{ 78 " General Settings {{{
253 " Ctrl-P should manage the working directory. 256 " Ctrl-P should manage the working directory.
254 let g:ctrlp_working_path_mode = 'ra' 257 let g:ctrlp_working_path_mode = 'ra'
255 258
256 " Ctrl-P should however ignore some stuff. 259 " Ctrl-P should however ignore some stuff.
257 let g:ctrlp_custom_ignore = { 260 let g:ctrlp_custom_ignore = {
258 \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$' 261 \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$'
259 \ } 262 \ }
260 263
261 " Make Ctrl-P cache stuff in our temp directory. 264 " Make Ctrl-P cache stuff in our temp directory.
262 let g:ctrlp_cache_dir = s:vim_home.'/cache' 265 let g:ctrlp_cache_dir = s:vim_home.'/cache'
263 266
264 " Remember things. 267 " Remember things.
272 \'tag', 'buffertag', 'quickfix', 'mixed', 'bookmarkdir', 275 \'tag', 'buffertag', 'quickfix', 'mixed', 'bookmarkdir',
273 \'autoignore' 276 \'autoignore'
274 \] 277 \]
275 278
276 " Use PyMatch to go faster. 279 " Use PyMatch to go faster.
277 if has('python3') || has('python') 280 if (has('python3') || has('python')) && s:HasPlugin('ctrlp-py-matcher')
278 let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'} 281 let g:ctrlp_match_func = {'match': 'pymatcher#PyMatch'}
279 let g:ctrlp_max_files = 0 282 let g:ctrlp_max_files = 0
280 let g:ctrlp_lazy_update = 350 283 let g:ctrlp_lazy_update = 350
281 endif 284 endif
282 285
283 " }}} 286 " }}}
284 287
285 " FZF {{{ 288 " FZF {{{
286 289
287 290 if s:vim_platform == 'mac'
291 if filereadable('/usr/local/opt/fzf/plugin/fzf.vim')
292 " FZF installed via Homebrew.
293 source /usr/local/opt/fzf/plugin/fzf.vim
294 endif
295 endif
296
297 let g:fzf_action = {
298 \'ctrl-t': 'tab split',
299 \'ctrl-v': 'vsplit',
300 \'ctrl-x': 'split',
301 \}
288 302
289 " }}} 303 " }}}
290 304
291 " Gutentags {{{ 305 " Gutentags {{{
292 306
639 nnoremap n nzvzz 653 nnoremap n nzvzz
640 nnoremap N Nzvzz 654 nnoremap N Nzvzz
641 655
642 " YCM mappings. 656 " YCM mappings.
643 if s:HasPlugin('youcompleteme') 657 if s:HasPlugin('youcompleteme')
644 augroup VimRC_YouCompleteMe 658 augroup VimRC_YouCompleteMe
645 autocmd! 659 autocmd!
646 autocmd FileType cpp nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv 660 autocmd FileType cpp nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>zv
647 autocmd FileType cpp nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>zv 661 autocmd FileType cpp nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>zv
648 autocmd FileType cpp nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>zv 662 autocmd FileType cpp nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>zv
649 autocmd FileType cpp nnoremap <Leader>ji :YcmCompleter GoToInclude<cr> 663 autocmd FileType cpp nnoremap <Leader>ji :YcmCompleter GoToInclude<cr>
650 autocmd FileType cpp nnoremap <Leader>jc :YcmCompleter GetDoc<cr> 664 autocmd FileType cpp nnoremap <Leader>jc :YcmCompleter GetDoc<cr>
651 autocmd FileType cpp nnoremap <Leader>je :YcmShowDetailedDiagnostic<cr> 665 autocmd FileType cpp nnoremap <Leader>je :YcmShowDetailedDiagnostic<cr>
652 augroup END 666 augroup END
653 endif 667 endif
654 668
655 " OmniSharp mappings 669 " OmniSharp mappings
656 if s:HasPlugin('OmniSharp') 670 if s:HasPlugin('OmniSharp')
657 augroup VimRC_OmniSharp 671 augroup VimRC_OmniSharp
658 autocmd! 672 autocmd!
659 autocmd FileType cs setlocal omnifunc=OmniSharp#Complete 673 autocmd FileType cs setlocal omnifunc=OmniSharp#Complete
660 autocmd BufEnter,TextChanged,InsertLeave *.cs SyntasticCheck 674 autocmd BufEnter,TextChanged,InsertLeave *.cs SyntasticCheck
661 autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation() 675 autocmd CursorHold *.cs call OmniSharp#TypeLookupWithoutDocumentation()
662 autocmd FileType cs nnoremap <Leader>jj :OmniSharpGotoDefinition<cr> 676 autocmd FileType cs nnoremap <Leader>jj :OmniSharpGotoDefinition<cr>
663 autocmd FileType cs nnoremap <Leader>x :OmniSharpFixIssue<cr> 677 autocmd FileType cs nnoremap <Leader>x :OmniSharpFixIssue<cr>
664 autocmd FileType cs nnoremap <Leader>fx :OmniSharpFixUsings<cr> 678 autocmd FileType cs nnoremap <Leader>fx :OmniSharpFixUsings<cr>
665 autocmd FileType cs nnoremap <Leader>tt :OmniSharpTypeLookup<cr> 679 autocmd FileType cs nnoremap <Leader>tt :OmniSharpTypeLookup<cr>
666 autocmd FileType cs nnoremap <Leader>dc :OmniSharpDocumentation<cr> 680 autocmd FileType cs nnoremap <Leader>dc :OmniSharpDocumentation<cr>
667 augroup END 681 augroup END
668 endif 682 endif
669 683
670 " ProjectRoot mappings 684 " ProjectRoot mappings
671 let s:no_auto_projectroot_buftypes = [ 685 let s:no_auto_projectroot_buftypes = [
672 \'help', 'nofile', 'quickfix'] 686 \'help', 'nofile', 'quickfix']
673 687
674 function! s:AutoProjectRootCD() abort 688 function! s:AutoProjectRootCD() abort
675 try 689 try
676 if index(s:no_auto_projectroot_buftypes, &buftype) == -1 690 if index(s:no_auto_projectroot_buftypes, &buftype) == -1
677 ProjectRootCD 691 ProjectRootCD
678 endif 692 endif
679 catch 693 catch
680 " Silently ignore invalid buffers 694 " Silently ignore invalid buffers
681 endtry 695 endtry
682 endfunction 696 endfunction
683 697
684 augroup VimRC_ProjectRoot 698 augroup VimRC_ProjectRoot
685 autocmd! 699 autocmd!
686 autocmd BufEnter * call <SID>AutoProjectRootCD() 700 autocmd BufEnter * call <SID>AutoProjectRootCD()
687 augroup END 701 augroup END
688 702
689 nnoremap <leader>cd :ProjectRootCD<cr> 703 nnoremap <leader>cd :ProjectRootCD<cr>
690 704
691 " Ctrl-P mappings. 705 " Ctrl-P mappings.
692 if s:HasPlugin('ctrlp') 706 if s:HasPlugin('ctrlp')
693 nnoremap <silent> <C-p> :CtrlP<cr> 707 nnoremap <silent> <C-p> :CtrlP<cr>
694 nnoremap <silent> <C-o> :CtrlPBuffer<cr> 708 nnoremap <silent> <C-o> :CtrlPBuffer<cr>
695 nnoremap <silent> <C-u> :CtrlPTag<cr> 709 nnoremap <silent> <C-u> :CtrlPTag<cr>
696 nnoremap <silent> <C-y> :CtrlPBufTag<cr> 710 nnoremap <silent> <C-y> :CtrlPBufTag<cr>
697 nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> 711 nnoremap <silent> <Tab> :CtrlPMRUFiles<cr>
698 nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> 712 nnoremap <silent> <F8> :CtrlPBookmarkDir<cr>
699 endif 713 endif
700 714
701 " FZF mappings. 715 " FZF mappings.
702 if s:HasPlugin('fzf') 716 if s:HasPlugin('fzf')
703 nnoremap <silent> <C-p> :Files<cr> 717 if exists('*fzf#run')
704 nnoremap <silent> <C-o> :Buffers<cr> 718 nnoremap <silent> <C-p> :Files<cr>
705 nnoremap <Tab> :History<cr> 719 nnoremap <silent> <C-o> :Buffers<cr>
720 nnoremap <Tab> :History<cr>
721 else
722 call ludo#error(
723 \"FZF is installed and enabled, but the Vim plugin ".
724 \"isn't loaded... add it to your `vimrc-local-pre`.")
725 endif
706 endif 726 endif
707 727
708 " }}} 728 " }}}
709 729
710 " Folding {{{ 730 " Folding {{{
770 ProjectRootExe NERDTreeFind 790 ProjectRootExe NERDTreeFind
771 normal zz 791 normal zz
772 endfunction 792 endfunction
773 793
774 function! s:ToggleCppFolding() abort 794 function! s:ToggleCppFolding() abort
775 if (&foldmethod == "syntax") 795 if (&foldmethod == "syntax")
776 setlocal foldmethod=manual 796 setlocal foldmethod=manual
777 setlocal nofoldenable 797 setlocal nofoldenable
778 else 798 else
779 setlocal foldmethod=syntax 799 setlocal foldmethod=syntax
780 setlocal foldenable 800 setlocal foldenable
781 endif 801 endif
782 endfunction 802 endfunction
783 803
784 " }}} 804 " }}}
785 805
786 " Local override {{{ 806 " Local override {{{