]> git.rmz.io Git - dotfiles.git/commitdiff
vim/cpp: Open all namespace and class folds
authorSamir Benmendil <sb@cad-scan.co.uk>
Thu, 24 Sep 2015 14:17:27 +0000 (15:17 +0100)
committerSamir Benmendil <sb@cad-scan.co.uk>
Wed, 4 Nov 2015 10:52:22 +0000 (10:52 +0000)
vim/ftplugin/cpp.vim

index a12e2d46ea5af5e6ace11b5d7882307818a600c9..b98aee201b55bd53a2f4c19841c3539e782f7cd0 100644 (file)
@@ -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()