Add codes below to ~/.vimrc
and run vim +PluginClean +PluginInstall +qa
:
" JavaScript code folding
set foldmethod=syntax
set foldlevelstart=3
let javaScript_fold=1
Plugin 'pangloss/vim-javascript'
Frequently used folding shortcuts:
zr/zm: decrease/increase the foldlevel by one;
zR/zM: open/close all folds;
zo/zc: open/close fold at cursor;
zO/zC: open/close all folds;
Ref:
http://stackoverflow.com/questions/4789605/how-do-i-enable-automatic-folds-in-vim https://www.linux.com/learn/tutorials/442438-vim-tips-folding-fun