Sunday, October 12, 2014

Save state of the folds: mkview

I have tried in the past to use fold, but found them to be cumbersome and unwieldy. Most problematic of all, was that the VIM doesn't save state of the fold: reopening the file with folds presents you with an useless screen showing you how many top level fold there are in the file. Real useless.

But as it turned out, VIM has a feature to preserve state of folds between sessions: views.

After some time googling, I have stumbled on this tip. The .vimrc's code is fairly trivial (when you know what to look for):


autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview 

Every time one closes a file,VIM would save under ~/.vim/view/ (default, see 'viewdir') the view information for the file. Every time one opens a file, VIM would try to restore the view information. And the state of the fold with it.