# HG changeset patch # User Ludovic Chabant # Date 1516321487 28800 # Node ID 4a2468f72e4408cce9aabe82616743ea74fe8104 # Parent 0ca43d6019195626c4a6086e62b3bb5ed4291974 Optimize C++ file editing with some folding tricks. diff -r 0ca43d601919 -r 4a2468f72e44 vim/vimrc --- a/vim/vimrc Wed Dec 20 09:19:14 2017 -0800 +++ b/vim/vimrc Thu Jan 18 16:24:47 2018 -0800 @@ -475,6 +475,8 @@ au! autocmd FileType c,c++,cpp setlocal foldmethod=syntax autocmd FileType c,c++,cpp setlocal colorcolumn=120 + autocmd FileType c,c++,cpp setlocal synmaxcol=200 + autocmd FileType c,c++,cpp nnoremap z :call ToggleCppFolding() augroup END augroup VimRCFileType_csharp @@ -482,6 +484,7 @@ autocmd BufNewFile,BufRead *.xaml setlocal filetype=xml autocmd FileType cs setlocal foldmethod=syntax autocmd FileType cs setlocal colorcolumn=120 + autocmd FileType cs setlocal synmaxcol=200 augroup END augroup VimRCFileType_css @@ -705,6 +708,13 @@ " Create folds with (in visual mode). vnoremap zf +" See http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text +" Don't screw up folds when inserting text that might affect them, until +" leaving insert mode. Foldmethod is local to the window. Protect against +" screwing up folding when switching between windows. +autocmd InsertEnter * if !exists('w:last_fdm') | let w:last_fdm=&foldmethod | setlocal foldmethod=manual | endif +autocmd InsertLeave,WinLeave * if exists('w:last_fdm') | let &l:foldmethod=w:last_fdm | unlet w:last_fdm | endif + " }}} " Abbreviations {{{ @@ -745,6 +755,16 @@ normal zz endfunction +function! s:ToggleCppFolding() abort + if (&foldmethod == "syntax") + setlocal foldmethod=manual + setlocal nofoldenable + else + setlocal foldmethod=syntax + setlocal foldenable + endif +endfunction + " }}} " Local override {{{