]> git.rmz.io Git - dotfiles.git/blobdiff - vim/ftplugin/cpp.vim
vim/cpp: Open all namespace and class folds
[dotfiles.git] / 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()