Mercurial > dotfiles
diff 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 |
line wrap: on
line diff
--- a/vim/vimrc Sat Feb 25 21:22:12 2017 -0800 +++ b/vim/vimrc Sat Feb 25 21:31:02 2017 -0800 @@ -359,18 +359,81 @@ " }}} +" Lightline {{{ +let g:lightline = { + \'colorscheme': 'solarized', + \'active': { + \ 'left': [ ['mode', 'paste'], + \ ['fugitive', 'lawrencium', 'readonly', 'filename'], + \ ['ctrlpmark'] ], + \ 'right': [ ['lineinfo'], + \ ['percent'], + \ ['fileformat', 'fileencoding', 'filetype'], + \ ['gutentags', 'syntastic', 'ycm_errs', 'ycm_warns'] ] + \ }, + \'component_function': { + \ 'fugitive': '_LightlineFugitive', + \ 'lawrencium': '_LightlineLawrencium', + \ 'ctrlpmark': '_LightlineCtrlPMark', + \ }, + \'component_expand': { + \ 'syntastic': '_LightlineSyntastic', + \ 'ycm_errs': '_LightlineYcmErrors', + \ 'ycm_warns': '_LightlineYcmWarnings', + \ 'gutentags': '_LightlineGutentags', + \ }, + \'component_type': { + \ 'syntastic': 'error', + \ 'ycm_errs': 'error', + \ 'ycm_warns': 'warning', + \ 'gutentags': 'warning', + \ }, + \} + +function! _LightlineFugitive() + return fugitive#head() +endfunction + +function! _LightlineLawrencium() + return lawrencium#statusline() +endfunction + +function! _LightlineCtrlPMark() + if expand('%:t') =~ 'ControlP' && has_key(g:lightline, 'ctrlp_item') + call lightline#link('iR'[g:lightline.ctrlp_regex]) + return lightline#concatenate( + \['WAT?', g:lightline.ctrlp_prev, + \ g:lightline.ctrlp_item, + \ g:lightline.ctrlp_next], + \0) + else + return '' + endif +endfunction + +function! _LightlineGutentags() + return gutentags#statusline() +endfunction + +function! _LightlineSyntastic() + return SyntasticStatuslineFlag() +endfunction + +function! _LightlineYcmErrors() + let l:cnt = youcompleteme#GetErrorCount() + return l:cnt > 0 ? string(l:cnt) : '' +endfunction + +function! _LightlineYcmWarnings() + let l:cnt = youcompleteme#GetWarningCount() + return l:cnt > 0 ? string(l:cnt) : '' +endfunction +" }}} + " }}} " File-Specific Settings {{{ -" Automatically change the current working directory based on a project -" I'm in. -augroup VimRCAutoCWD - au! - autocmd BufReadPost * call s:SetProjectRootCwd(1) - autocmd BufEnter * call s:SetProjectRootCwd(0) -augroup END - augroup VimRCFileType_markdown au! autocmd FileType text,markdown setlocal textwidth=80 @@ -428,8 +491,6 @@ noremap <C-Tab> :tabnext<cr> noremap <C-S-Tab> :tabprevious<cr> nnoremap <leader>t :tabnew<cr> -nnoremap <C-t> :tabnew<cr> -nnoremap <C-w> :tabclose<cr> " Window navigation nnoremap <C-up> :wincmd k<cr> @@ -479,7 +540,7 @@ nnoremap <silent> <C-p> :CtrlP<cr> nnoremap <silent> <C-o> :CtrlPBuffer<cr> nnoremap <silent> <C-u> :CtrlPTag<cr> -nnoremap <silent> <C-y> :CtrlPQuickfix<cr> +nnoremap <silent> <C-y> :CtrlPBufTag<cr> nnoremap <silent> <Tab> :CtrlPMRUFiles<cr> nnoremap <silent> <F8> :CtrlPBookmarkDir<cr> @@ -546,6 +607,13 @@ nnoremap n nzvzz nnoremap N Nzvzz +" YCM mappings. +nnoremap <Leader>jj :YcmCompleter GoToImprecise<cr> +nnoremap <Leader>jd :YcmCompleter GoToDefinition<cr> +nnoremap <Leader>jh :YcmCompleter GoToDeclaration<cr> +nnoremap <Leader>ji :YcmCompleter GoToInclude<cr> +nnoremap <Leader>jc :YcmCompleter GetDoc<cr> + " }}} " Folding {{{ @@ -572,43 +640,6 @@ " }}} -" Status Line {{{ - -set statusline=%f " Path. -set statusline+=%m " Modified flag. -set statusline+=%r " Readonly flag. -set statusline+=%w " Preview window flag. - -set statusline+=\ " Space. - -set statusline+=%#redbar# " Highlight the following as a warning. -set statusline+=%{SyntasticStatuslineFlag()} " Syntastic errors. -set statusline+=%* " Reset highlighting. - -set statusline+=%= " Right align. - -" Tag file generation indicator. -set statusline+=%{gutentags#statusline('[TAGS]')} -set statusline+=\ " Space. - -" Mercurial information. -set statusline+=%{lawrencium#statusline('[',']')} -set statusline+=\ " Space. - -" File format, encoding and type. Ex: "(unix/utf-8/python)" -set statusline+=( -set statusline+=%{&ff} " Format (unix/DOS). -set statusline+=/ -set statusline+=%{strlen(&fenc)?&fenc:&enc} " Encoding (utf-8). -set statusline+=/ -set statusline+=%{&ft} " Type (python). -set statusline+=) - -" Line and column position and counts. -set statusline+=\ (%l\/%L,%03c) - -" }}} - " Functions {{{ function! s:ToggleSpellCheck() abort @@ -630,62 +661,6 @@ call cursor(l, c) endfunction -function! s:FindProjectRoot(cur, marker) abort - let l:cur = a:cur - let l:previous_cur = '' - let l:slash = '/' - if has('win32') - let l:slash = '\' - endif - while l:cur != l:previous_cur - let l:marker_path = l:cur . l:slash . a:marker - if glob(l:marker_path) != '' - return fnamemodify(l:cur, ':p') - endif - let l:previous_cur = l:cur - let l:cur = fnamemodify(l:cur, ':h') - endwhile - return '' -endfunction - -function! s:SetProjectRootCwd(recompute) abort - if a:recompute != 1 && exists('b:ludo_workdir') - execute 'lcd!' fnameescape(b:ludo_workdir) - return - endif - - let l:cur_file_dir = expand('%:p:h', 1) - if l:cur_file_dir =~ '\v^(\w+:)?(//|\\\\)' - " Don't do shit on filenames coming from the network or something. - return - endif - let l:found_root = 0 - let l:root = '' - let l:markers = [] - if exists('g:ctrlp_root_markers') - let l:markers += g:ctrlp_root_markers - endif - let l:markers += ['.git', '.hg', '.svn', '.bzr', '_darcs'] - let l:unique_markers = [] - for marker in l:markers - if index(l:unique_markers, marker) < 0 - call add(l:unique_markers, marker) - endif - endfor - " Find the project root closest to the current file. - for marker in l:unique_markers - let l:proj_root = s:FindProjectRoot(l:cur_file_dir, marker) - if l:proj_root != '' && len(l:proj_root) > len(l:root) - let l:root = l:proj_root - let l:found_root = 1 - endif - endfor - if l:found_root - let b:ludo_workdir = l:root - execute 'lcd!' fnameescape(l:root) - endif -endfunction - function! s:ToggleNERDTree() abort NERDTreeToggle endfunction