Mercurial > dotfiles
comparison vim/vimrc @ 176:c6a072353606
Vim config changes:
* Better working dir management in `vimrc`.
* Better shortcuts for NERDTree and CtrlP.
* Misc stuff.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 20 Jul 2014 17:43:25 -0700 |
parents | 393449253540 |
children | 8b37877d309f |
comparison
equal
deleted
inserted
replaced
175:095fb39b2096 | 176:c6a072353606 |
---|---|
242 | 242 |
243 " File-Specific Settings {{{ | 243 " File-Specific Settings {{{ |
244 | 244 |
245 if has("autocmd") | 245 if has("autocmd") |
246 | 246 |
247 augroup VimRCAutoCWD | |
248 au! | |
249 | |
250 autocmd BufEnter * call s:SetProjectRootCwd() | |
251 augroup END | |
252 | |
247 augroup VimRCFileTypeSettings | 253 augroup VimRCFileTypeSettings |
248 au! | 254 au! |
249 | 255 |
250 " Nice text width for text files. | 256 " Nice text width for text files. |
251 autocmd FileType text,markdown setlocal textwidth=80 | 257 autocmd FileType text,markdown setlocal textwidth=80 |
280 noremap <end> g<end> | 286 noremap <end> g<end> |
281 | 287 |
282 " Tab navigation | 288 " Tab navigation |
283 nnoremap <C-Tab> :tabnext<cr> | 289 nnoremap <C-Tab> :tabnext<cr> |
284 nnoremap <C-S-Tab> :tabprevious<cr> | 290 nnoremap <C-S-Tab> :tabprevious<cr> |
285 nnoremap <C-W> :tabclose<cr> | |
286 | 291 |
287 " Buffer navigation | 292 " Buffer navigation |
288 nnoremap <C-S-right> :bnext<cr> | 293 nnoremap <C-S-right> :bnext<cr> |
289 nnoremap <C-S-left> :bprevious<cr> | 294 nnoremap <C-S-left> :bprevious<cr> |
290 | 295 |
292 nnoremap <C-up> :wincmd k<cr> | 297 nnoremap <C-up> :wincmd k<cr> |
293 nnoremap <C-down> :wincmd j<cr> | 298 nnoremap <C-down> :wincmd j<cr> |
294 nnoremap <C-left> :wincmd h<cr> | 299 nnoremap <C-left> :wincmd h<cr> |
295 nnoremap <C-right> :wincmd l<cr> | 300 nnoremap <C-right> :wincmd l<cr> |
296 | 301 |
297 " Open NERDtree. | |
298 nnoremap <F2> :NERDTreeToggle %:p:h<cr> | |
299 | |
300 " Switch buffers. | 302 " Switch buffers. |
301 nnoremap <F3> :execute ("buffer " . bufname("#"))<cr> | 303 nnoremap <F2> :execute ("buffer " . bufname("#"))<cr> |
304 | |
305 " NERDTree. | |
306 nnoremap <F3> :call <SID>ToggleNERDTree()<cr> | |
307 nnoremap <F4> :call <SID>FindInNERDTree()<cr> | |
302 | 308 |
303 " Tagbar. | 309 " Tagbar. |
304 nnoremap <F8> :TagbarToggle<cr> | 310 nnoremap <F5> :TagbarToggle<cr> |
311 nnoremap <F6> :TagbarOpenAutoClose<cr> | |
305 | 312 |
306 " Common typos. | 313 " Common typos. |
307 nnoremap ; : | 314 nnoremap ; : |
308 | 315 |
309 " Split windows | 316 " Split windows |
328 nnoremap <leader><space> :noh<cr>:call clearmatches()<cr> | 335 nnoremap <leader><space> :noh<cr>:call clearmatches()<cr> |
329 | 336 |
330 " Ctrl-P mappings. | 337 " Ctrl-P mappings. |
331 nnoremap <silent> <C-p> :CtrlP<cr> | 338 nnoremap <silent> <C-p> :CtrlP<cr> |
332 nnoremap <silent> <C-o> :CtrlPBuffer<cr> | 339 nnoremap <silent> <C-o> :CtrlPBuffer<cr> |
333 nnoremap <silent> <C-i> :CtrlPMRU<cr> | 340 nnoremap <silent> <C-i> :CtrlPTag<cr> |
341 nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> | |
334 | 342 |
335 " Switch between FR and US keyboard layouts. | 343 " Switch between FR and US keyboard layouts. |
336 nnoremap <C-l>f :setlocal keymap=french<cr> | 344 nnoremap <C-l>f :setlocal keymap=french<cr> |
337 nnoremap <C-l>u :setlocal keymap=<cr> | 345 nnoremap <C-l>u :setlocal keymap=<cr> |
338 | 346 |
428 %s/\s\+$//e | 436 %s/\s\+$//e |
429 let @/='' | 437 let @/='' |
430 call cursor(l, c) | 438 call cursor(l, c) |
431 endfunction | 439 endfunction |
432 | 440 |
441 function! s:FindProjectRoot(cur, marker) abort | |
442 let l:cur = a:cur | |
443 let l:previous_cur = '' | |
444 let l:slash = '/' | |
445 if has('win32') | |
446 let l:slash = '\\' | |
447 endif | |
448 while l:cur != l:previous_cur | |
449 let l:marker_path = l:cur . l:slash . a:marker | |
450 if glob(l:marker_path) != '' | |
451 return fnamemodify(l:cur, ':p') | |
452 endif | |
453 let l:previous_cur = l:cur | |
454 let l:cur = fnamemodify(l:cur, ':h') | |
455 endwhile | |
456 return '' | |
457 endfunction | |
458 | |
459 function! s:SetProjectRootCwd() abort | |
460 let l:cur_file_dir = expand('%:p:h', 1) | |
461 if l:cur_file_dir =~ '\v^.+://' | |
462 return | |
463 endif | |
464 let l:root = l:cur_file_dir | |
465 let l:markers = g:ctrlp_root_markers[:] | |
466 let l:markers += ['.git', '.hg', '.svn', '.bzr', '_darcs'] | |
467 for marker in l:markers | |
468 let l:proj_root = s:FindProjectRoot(l:cur_file_dir, marker) | |
469 if l:proj_root != '' | |
470 let l:root = l:proj_root | |
471 break | |
472 endif | |
473 endfor | |
474 execute 'lcd!' fnameescape(l:root) | |
475 endfunction | |
476 | |
477 function! s:ToggleNERDTree() abort | |
478 let l:was_open = nerdtree#isTreeOpen() | |
479 NERDTreeToggle | |
480 if !l:was_open | |
481 wincmd p | |
482 NERDTreeCWD | |
483 wincmd p | |
484 NERDTreeFind | |
485 endif | |
486 endfunction | |
487 | |
488 function! s:FindInNERDTree() abort | |
489 if !nerdtree#isTreeOpen() | |
490 call s:ToggleNERDTree() | |
491 else | |
492 if getbufvar('%', 'NERDTreeType') != '' | |
493 wincmd p | |
494 else | |
495 NERDTreeFind | |
496 endif | |
497 endif | |
498 endfunction | |
499 | |
433 " }}} | 500 " }}} |
434 | 501 |
435 " Temporary stuff {{{ | 502 " Temporary stuff {{{ |
436 | 503 |
437 " Enable debugging Lawrencium | 504 " Enable debugging Lawrencium |
439 let g:lawrencium_trace = 0 | 506 let g:lawrencium_trace = 0 |
440 | 507 |
441 command! LawrenciumEnableTrace :call lawrencium#debugtrace(1) | 508 command! LawrenciumEnableTrace :call lawrencium#debugtrace(1) |
442 command! LawrenciumDisableTrace :call lawrencium#debugtrace(0) | 509 command! LawrenciumDisableTrace :call lawrencium#debugtrace(0) |
443 | 510 |
511 let g:autotags_debug = 1 | |
512 | |
444 " Enable debugging PieCrust | 513 " Enable debugging PieCrust |
445 let g:piecrust_debug = 1 | 514 let g:piecrust_debug = 1 |
446 let g:piecrust_trace = 0 | 515 let g:piecrust_trace = 0 |
447 | 516 |
448 " }}} | 517 " }}} |