From e7dcb01eced1027f952356599f1e43f1ee8083eb Mon Sep 17 00:00:00 2001 From: Samir Benmendil Date: Thu, 24 Sep 2015 15:17:27 +0100 Subject: [PATCH] vim/cpp: Open all namespace and class folds --- vim/ftplugin/cpp.vim | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/vim/ftplugin/cpp.vim b/vim/ftplugin/cpp.vim index a12e2d4..b98aee2 100644 --- a/vim/ftplugin/cpp.vim +++ b/vim/ftplugin/cpp.vim @@ -1,5 +1,3 @@ -setlocal foldmethod=syntax - setlocal textwidth=100 " indent 4 spaces @@ -20,3 +18,15 @@ augroup fswitch au BufEnter *.h let b:fswitchdst = 'cpp,c' au BufEnter *.h let b:fswitchlocs = 'reg:/include/source/' augroup END + +setlocal foldmethod=syntax +" set foldlevel according to number of matches of 'namespace' and 'class' not +" containing ';' +function! InitialFoldLevel() + let v:errmsg = "" + keepjumps keeppatterns silent! 1,/}/s/^\(namespace\|class\) \+[^;]*$//n + if v:errmsg == "" + let &foldlevel=str2nr(split(v:statusmsg)[0]) + endif +endf +call InitialFoldLevel() -- 2.48.1