comparison vim/vimrc @ 379:58410650ce36

Add lightline and remove old scratch. Customize Vim settings.
author Ludovic Chabant <ludovic@chabant.com>
date Sat, 25 Feb 2017 21:31:02 -0800
parents 083360925deb
children af7646eceddc d367df6afcad
comparison
equal deleted inserted replaced
378:5ae26582454e 379:58410650ce36
357 357
358 let g:pymode_rope = 0 358 let g:pymode_rope = 0
359 359
360 " }}} 360 " }}}
361 361
362 " Lightline {{{
363 let g:lightline = {
364 \'colorscheme': 'solarized',
365 \'active': {
366 \ 'left': [ ['mode', 'paste'],
367 \ ['fugitive', 'lawrencium', 'readonly', 'filename'],
368 \ ['ctrlpmark'] ],
369 \ 'right': [ ['lineinfo'],
370 \ ['percent'],
371 \ ['fileformat', 'fileencoding', 'filetype'],
372 \ ['gutentags', 'syntastic', 'ycm_errs', 'ycm_warns'] ]
373 \ },
374 \'component_function': {
375 \ 'fugitive': '_LightlineFugitive',
376 \ 'lawrencium': '_LightlineLawrencium',
377 \ 'ctrlpmark': '_LightlineCtrlPMark',
378 \ },
379 \'component_expand': {
380 \ 'syntastic': '_LightlineSyntastic',
381 \ 'ycm_errs': '_LightlineYcmErrors',
382 \ 'ycm_warns': '_LightlineYcmWarnings',
383 \ 'gutentags': '_LightlineGutentags',
384 \ },
385 \'component_type': {
386 \ 'syntastic': 'error',
387 \ 'ycm_errs': 'error',
388 \ 'ycm_warns': 'warning',
389 \ 'gutentags': 'warning',
390 \ },
391 \}
392
393 function! _LightlineFugitive()
394 return fugitive#head()
395 endfunction
396
397 function! _LightlineLawrencium()
398 return lawrencium#statusline()
399 endfunction
400
401 function! _LightlineCtrlPMark()
402 if expand('%:t') =~ 'ControlP' && has_key(g:lightline, 'ctrlp_item')
403 call lightline#link('iR'[g:lightline.ctrlp_regex])
404 return lightline#concatenate(
405 \['WAT?', g:lightline.ctrlp_prev,
406 \ g:lightline.ctrlp_item,
407 \ g:lightline.ctrlp_next],
408 \0)
409 else
410 return ''
411 endif
412 endfunction
413
414 function! _LightlineGutentags()
415 return gutentags#statusline()
416 endfunction
417
418 function! _LightlineSyntastic()
419 return SyntasticStatuslineFlag()
420 endfunction
421
422 function! _LightlineYcmErrors()
423 let l:cnt = youcompleteme#GetErrorCount()
424 return l:cnt > 0 ? string(l:cnt) : ''
425 endfunction
426
427 function! _LightlineYcmWarnings()
428 let l:cnt = youcompleteme#GetWarningCount()
429 return l:cnt > 0 ? string(l:cnt) : ''
430 endfunction
431 " }}}
432
362 " }}} 433 " }}}
363 434
364 " File-Specific Settings {{{ 435 " File-Specific Settings {{{
365
366 " Automatically change the current working directory based on a project
367 " I'm in.
368 augroup VimRCAutoCWD
369 au!
370 autocmd BufReadPost * call s:SetProjectRootCwd(1)
371 autocmd BufEnter * call s:SetProjectRootCwd(0)
372 augroup END
373 436
374 augroup VimRCFileType_markdown 437 augroup VimRCFileType_markdown
375 au! 438 au!
376 autocmd FileType text,markdown setlocal textwidth=80 439 autocmd FileType text,markdown setlocal textwidth=80
377 autocmd FileType markdown nnoremap <buffer> <localleader>1 yypVr=:redraw<cr> 440 autocmd FileType markdown nnoremap <buffer> <localleader>1 yypVr=:redraw<cr>
426 489
427 " Tab navigation 490 " Tab navigation
428 noremap <C-Tab> :tabnext<cr> 491 noremap <C-Tab> :tabnext<cr>
429 noremap <C-S-Tab> :tabprevious<cr> 492 noremap <C-S-Tab> :tabprevious<cr>
430 nnoremap <leader>t :tabnew<cr> 493 nnoremap <leader>t :tabnew<cr>
431 nnoremap <C-t> :tabnew<cr>
432 nnoremap <C-w> :tabclose<cr>
433 494
434 " Window navigation 495 " Window navigation
435 nnoremap <C-up> :wincmd k<cr> 496 nnoremap <C-up> :wincmd k<cr>
436 nnoremap <C-down> :wincmd j<cr> 497 nnoremap <C-down> :wincmd j<cr>
437 nnoremap <C-left> :wincmd h<cr> 498 nnoremap <C-left> :wincmd h<cr>
477 538
478 " Ctrl-P mappings. 539 " Ctrl-P mappings.
479 nnoremap <silent> <C-p> :CtrlP<cr> 540 nnoremap <silent> <C-p> :CtrlP<cr>
480 nnoremap <silent> <C-o> :CtrlPBuffer<cr> 541 nnoremap <silent> <C-o> :CtrlPBuffer<cr>
481 nnoremap <silent> <C-u> :CtrlPTag<cr> 542 nnoremap <silent> <C-u> :CtrlPTag<cr>
482 nnoremap <silent> <C-y> :CtrlPQuickfix<cr> 543 nnoremap <silent> <C-y> :CtrlPBufTag<cr>
483 nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> 544 nnoremap <silent> <Tab> :CtrlPMRUFiles<cr>
484 nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> 545 nnoremap <silent> <F8> :CtrlPBookmarkDir<cr>
485 546
486 " Switch between FR and US keyboard layouts. 547 " Switch between FR and US keyboard layouts.
487 nnoremap <C-l>f :setlocal keymap=french<cr> 548 nnoremap <C-l>f :setlocal keymap=french<cr>
544 605
545 " Keep search matches in the middle of the window. 606 " Keep search matches in the middle of the window.
546 nnoremap n nzvzz 607 nnoremap n nzvzz
547 nnoremap N Nzvzz 608 nnoremap N Nzvzz
548 609
610 " YCM mappings.
611 nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr>
612 nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr>
613 nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr>
614 nnoremap <Leader>ji :YcmCompleter GoToInclude<cr>
615 nnoremap <Leader>jc :YcmCompleter GetDoc<cr>
616
549 " }}} 617 " }}}
550 618
551 " Folding {{{ 619 " Folding {{{
552 620
553 " Start with one level of open. 621 " Start with one level of open.
567 " Abbreviations {{{ 635 " Abbreviations {{{
568 636
569 iabbrev @@ ludovic@chabant.com 637 iabbrev @@ ludovic@chabant.com
570 iabbrev ccopy Copyright &copy;2011 Ludovic Chabant, all rights reserved. 638 iabbrev ccopy Copyright &copy;2011 Ludovic Chabant, all rights reserved.
571 iabbrev ssig --<cr>l u d o .<cr>. 8 0 17 80 639 iabbrev ssig --<cr>l u d o .<cr>. 8 0 17 80
572
573 " }}}
574
575 " Status Line {{{
576
577 set statusline=%f " Path.
578 set statusline+=%m " Modified flag.
579 set statusline+=%r " Readonly flag.
580 set statusline+=%w " Preview window flag.
581
582 set statusline+=\ " Space.
583
584 set statusline+=%#redbar# " Highlight the following as a warning.
585 set statusline+=%{SyntasticStatuslineFlag()} " Syntastic errors.
586 set statusline+=%* " Reset highlighting.
587
588 set statusline+=%= " Right align.
589
590 " Tag file generation indicator.
591 set statusline+=%{gutentags#statusline('[TAGS]')}
592 set statusline+=\ " Space.
593
594 " Mercurial information.
595 set statusline+=%{lawrencium#statusline('[',']')}
596 set statusline+=\ " Space.
597
598 " File format, encoding and type. Ex: "(unix/utf-8/python)"
599 set statusline+=(
600 set statusline+=%{&ff} " Format (unix/DOS).
601 set statusline+=/
602 set statusline+=%{strlen(&fenc)?&fenc:&enc} " Encoding (utf-8).
603 set statusline+=/
604 set statusline+=%{&ft} " Type (python).
605 set statusline+=)
606
607 " Line and column position and counts.
608 set statusline+=\ (%l\/%L,%03c)
609 640
610 " }}} 641 " }}}
611 642
612 " Functions {{{ 643 " Functions {{{
613 644
628 let c = col(".") 659 let c = col(".")
629 %s/\s\+$//e 660 %s/\s\+$//e
630 call cursor(l, c) 661 call cursor(l, c)
631 endfunction 662 endfunction
632 663
633 function! s:FindProjectRoot(cur, marker) abort
634 let l:cur = a:cur
635 let l:previous_cur = ''
636 let l:slash = '/'
637 if has('win32')
638 let l:slash = '\'
639 endif
640 while l:cur != l:previous_cur
641 let l:marker_path = l:cur . l:slash . a:marker
642 if glob(l:marker_path) != ''
643 return fnamemodify(l:cur, ':p')
644 endif
645 let l:previous_cur = l:cur
646 let l:cur = fnamemodify(l:cur, ':h')
647 endwhile
648 return ''
649 endfunction
650
651 function! s:SetProjectRootCwd(recompute) abort
652 if a:recompute != 1 && exists('b:ludo_workdir')
653 execute 'lcd!' fnameescape(b:ludo_workdir)
654 return
655 endif
656
657 let l:cur_file_dir = expand('%:p:h', 1)
658 if l:cur_file_dir =~ '\v^(\w+:)?(//|\\\\)'
659 " Don't do shit on filenames coming from the network or something.
660 return
661 endif
662 let l:found_root = 0
663 let l:root = ''
664 let l:markers = []
665 if exists('g:ctrlp_root_markers')
666 let l:markers += g:ctrlp_root_markers
667 endif
668 let l:markers += ['.git', '.hg', '.svn', '.bzr', '_darcs']
669 let l:unique_markers = []
670 for marker in l:markers
671 if index(l:unique_markers, marker) < 0
672 call add(l:unique_markers, marker)
673 endif
674 endfor
675 " Find the project root closest to the current file.
676 for marker in l:unique_markers
677 let l:proj_root = s:FindProjectRoot(l:cur_file_dir, marker)
678 if l:proj_root != '' && len(l:proj_root) > len(l:root)
679 let l:root = l:proj_root
680 let l:found_root = 1
681 endif
682 endfor
683 if l:found_root
684 let b:ludo_workdir = l:root
685 execute 'lcd!' fnameescape(l:root)
686 endif
687 endfunction
688
689 function! s:ToggleNERDTree() abort 664 function! s:ToggleNERDTree() abort
690 NERDTreeToggle 665 NERDTreeToggle
691 endfunction 666 endfunction
692 667
693 function! s:FindInNERDTree() abort 668 function! s:FindInNERDTree() abort