comparison vim/vimrc @ 435:b7682004288d

Move Vim stuff to autoload, add FZF tags lister.
author Ludovic Chabant <ludovic@chabant.com>
date Wed, 04 Apr 2018 20:36:11 -0700
parents 71a080d4d83c
children f1f95a19fffe
comparison
equal deleted inserted replaced
434:44afdeba29bf 435:b7682004288d
17 if exists('g:sourced_vimrc') 17 if exists('g:sourced_vimrc')
18 let g:resourcing_vimrc = 1 18 let g:resourcing_vimrc = 1
19 endif 19 endif
20 let g:sourced_vimrc = 1 20 let g:sourced_vimrc = 1
21 21
22 " Get the platform we're running on.
23 if has("win32") || has("win64") || has("dos32")
24 let s:vim_platform = "windows"
25 let s:path_sep = "\\"
26 elseif has("mac")
27 let s:vim_platform = "mac"
28 let s:path_sep = '/'
29 else
30 let s:vim_platform = "unix"
31 let s:path_sep = '/'
32 endif
33
34 " Get our vim directory.
35 let s:vim_home = expand("<sfile>:h")
36
37 " Local pre-override. 22 " Local pre-override.
38 let s:local_vimrc_pre = s:vim_home.'/vimrc-local-pre' 23 let s:local_vimrc_pre = ludo#localpath('vimrc-local-pre')
39 if filereadable(s:local_vimrc_pre) 24 if filereadable(s:local_vimrc_pre)
40 execute 'source' s:local_vimrc_pre 25 execute 'source' s:local_vimrc_pre
41 endif 26 endif
42 27
43 " Make sure `filetype` stuff is turned off before loading Pathogen. 28 " Make sure `filetype` stuff is turned off before loading Pathogen.
44 syntax off 29 syntax off
45 filetype off 30 filetype off
46 31
47 " Disable some plugins. 32 " Disable some plugins.
48 let g:pathogen_disabled = get(g:, 'pathogen_disabled', []) 33 let g:pathogen_disabled = get(g:, 'pathogen_disabled', [])
49 call ludo#setup_pathogen([s:vim_home.'/bundle', s:vim_home.'/local']) 34 call ludo#setup_pathogen([ludo#localpath('bundle'), ludo#localpath('local')])
50 35
51 " Load pathogen. 36 " Load pathogen.
52 runtime bundle/pathogen/autoload/pathogen.vim 37 runtime bundle/pathogen/autoload/pathogen.vim
53 " Add the bundle directory, and potentially add the local one if it exists. 38 " Add the bundle directory, and potentially add the local one if it exists.
54 " Note that we pass absolute paths to make pathogen prepend stuff before Vim's 39 " Note that we pass absolute paths to make pathogen prepend stuff before Vim's
55 " system files otherwise stuff like indent plugins don't work. 40 " system files otherwise stuff like indent plugins don't work.
56 let s:pathogen_bundles = [s:vim_home.s:path_sep.'bundle'.s:path_sep.'{}'] 41 let s:pathogen_bundles = [ludo#localpath('bundle', '{}')]
57 if isdirectory(s:vim_home.s:path_sep.'local') 42 if isdirectory(ludo#localpath('local'))
58 call add(s:pathogen_bundles, s:vim_home.s:path_sep.'local'.s:path_sep.'{}') 43 call add(s:pathogen_bundles, ludo#localpath('local', '{}'))
59 endif 44 endif
60 call call('pathogen#infect', s:pathogen_bundles) 45 call call('pathogen#infect', s:pathogen_bundles)
61 46
62 " Hide the toolbar in MacVim/gVIM, and set a nice window size. 47 " Hide the toolbar in MacVim/gVIM, and set a nice window size.
63 if has("gui_running") && !exists('g:resourcing_vimrc') 48 if has("gui_running") && !exists('g:resourcing_vimrc')
141 " Don't pollute the hard-drive with *~ files. Only 126 " Don't pollute the hard-drive with *~ files. Only
142 " create them in hidden backup/temp directories while 127 " create them in hidden backup/temp directories while
143 " we edit the file, and then get rid of it. 128 " we edit the file, and then get rid of it.
144 set nobackup 129 set nobackup
145 set writebackup 130 set writebackup
146 execute('set backupdir='.s:vim_home.'/backup') 131 execute('set backupdir='.ludo#localpath('backup'))
147 execute('set directory='.s:vim_home.'/temp') 132 execute('set directory='.ludo#localpath('temp'))
148 133
149 " Better command-line completion, but don't show some 134 " Better command-line completion, but don't show some
150 " stuff we don't care about. 135 " stuff we don't care about.
151 set wildmenu 136 set wildmenu
152 set wildmode=list:longest 137 set wildmode=list:longest
198 " Column indicators. 183 " Column indicators.
199 set colorcolumn=72,79 184 set colorcolumn=72,79
200 185
201 " And now, for some system-dependent settings: 186 " And now, for some system-dependent settings:
202 " - font to use 187 " - font to use
203 if s:vim_platform == "windows" 188 if ludo#platform() == "windows"
204 set guifont=InputMono:h11,Hack:h12,Consolas:h12 189 set guifont=InputMono:h11,Hack:h12,Consolas:h12
205 else 190 else
206 set guifont=InputMono:h11,Hack:h12,Monaco:h12 191 set guifont=InputMono:h11,Hack:h12,Monaco:h12
207 endif 192 endif
208 193
253 if executable('ag') 238 if executable('ag')
254 let g:ackprg = 'ag --vimgrep' 239 let g:ackprg = 'ag --vimgrep'
255 endif 240 endif
256 241
257 nnoremap <Leader>a :Ack!<Space> 242 nnoremap <Leader>a :Ack!<Space>
243 nnoremap <leader>f :Ack! /<C-R><C-W>/
244 vnoremap <leader>f "zy:Ack! /<C-R>z/
258 245
259 " }}} 246 " }}}
260 247
261 " Ctrl-P {{{ 248 " Ctrl-P {{{
262 249
270 let g:ctrlp_custom_ignore = { 257 let g:ctrlp_custom_ignore = {
271 \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$' 258 \ 'dir': '\v[\/](\.git|\.hg|\.svn|venv|static|node_modules|_cache|_counter)$'
272 \ } 259 \ }
273 260
274 " Make Ctrl-P cache stuff in our temp directory. 261 " Make Ctrl-P cache stuff in our temp directory.
275 let g:ctrlp_cache_dir = s:vim_home.'/cache' 262 let g:ctrlp_cache_dir = ludo#localpath('cache')
276 263
277 " Remember things. 264 " Remember things.
278 let g:ctrlp_clear_cache_on_exit = 0 265 let g:ctrlp_clear_cache_on_exit = 0
279 266
280 " Don't include some stuff in the most recently used list. 267 " Don't include some stuff in the most recently used list.
295 282
296 " }}} 283 " }}}
297 284
298 " FZF {{{ 285 " FZF {{{
299 286
300 if s:vim_platform == 'mac' 287 if ludo#platform() == 'mac'
301 if filereadable('/usr/local/opt/fzf/plugin/fzf.vim') 288 if filereadable('/usr/local/opt/fzf/plugin/fzf.vim')
302 " FZF installed via Homebrew. 289 " FZF installed via Homebrew.
303 source /usr/local/opt/fzf/plugin/fzf.vim 290 source /usr/local/opt/fzf/plugin/fzf.vim
304 endif 291 endif
305 endif 292 endif
312 299
313 " }}} 300 " }}}
314 301
315 " Gutentags {{{ 302 " Gutentags {{{
316 303
317 let g:gutentags_cache_dir = s:vim_home.'/tags' 304 let g:gutentags_cache_dir = ludo#localpath('tags')
318 let g:gutentags_ctags_exclude = ['venv', 'build', 'static', 'node_modules'] 305 let g:gutentags_ctags_exclude = ['venv', 'build', 'static', 'node_modules']
319 let g:gutentags_ctags_extra_args = ['--options='.s:vim_home.'/ctagsrc'] 306 let g:gutentags_ctags_extra_args = ['--options='.ludo#localpath('ctagsrc')]
320 let g:gutentags_ctags_exclude_wildignore = 0 307 let g:gutentags_ctags_exclude_wildignore = 0
321 308
322 " }}} 309 " }}}
323 310
324 " Syntastic {{{ 311 " Syntastic {{{
654 let @@ = temp 641 let @@ = temp
655 endfunction 642 endfunction
656 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o> 643 vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR><c-o>
657 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o> 644 vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR><c-o>
658 645
659 nnoremap <leader>fa :vimgrep /<C-R><C-W>/
660 vnoremap <leader>fa "zy:vimgrep /<C-R>z/
661
662 " Keep search matches in the middle of the window. 646 " Keep search matches in the middle of the window.
663 nnoremap n nzvzz 647 nnoremap n nzvzz
664 nnoremap N Nzvzz 648 nnoremap N Nzvzz
665 649
666 " Writing mode. 650 " Writing mode.
731 if s:HasPlugin('fzf') 715 if s:HasPlugin('fzf')
732 if exists('*fzf#run') 716 if exists('*fzf#run')
733 nnoremap <silent> <C-p> :Files<cr> 717 nnoremap <silent> <C-p> :Files<cr>
734 nnoremap <silent> <C-o> :Buffers<cr> 718 nnoremap <silent> <C-o> :Buffers<cr>
735 nnoremap <Tab> :History<cr> 719 nnoremap <Tab> :History<cr>
720
721 " Replace the default `Tags` command, which requires Perl, with
722 " something I can use, based on Python.
723 command! -bang -nargs=* Tags call ludo#run_fzf_tags(<q-args>, <bang>0)
736 else 724 else
737 call ludo#error( 725 call ludo#error(
738 \"FZF is installed and enabled, but the Vim plugin ". 726 \"FZF is installed and enabled, but the Vim plugin ".
739 \"isn't loaded... add it to your `vimrc-local-pre`.") 727 \"isn't loaded... add it to your `vimrc-local-pre`.")
740 endif 728 endif
818 806
819 " }}} 807 " }}}
820 808
821 " Local override {{{ 809 " Local override {{{
822 810
823 let s:local_vimrc = s:vim_home.'/vimrc-local' 811 let s:local_vimrc = ludo#localpath('vimrc-local')
824 if filereadable(s:local_vimrc) 812 if filereadable(s:local_vimrc)
825 execute 'source' s:local_vimrc 813 execute 'source' s:local_vimrc
826 let s:local_vimrc = s:vim_home.'/vimrc-local' 814 endif
827 if filereadable(s:local_vimrc) 815
828 execute 'source' s:local_vimrc 816 " }}}
829 endif 817
830
831 " }}}
832