I am using vim to create and edit python code. I have python-mode installed which provides (amongst other things) refactoring via rope. I also have SimpylFold installed to provide code folding.
Everything's working great apart from one annoying little thing...
When I do a refactoring operation, all folds are automatically closed immediately. This is super annoying as I have the folds set to various states of open / closed as appropriate for what I'm working on at the time and this undoes that so I have to re-open the folds that I'm working on.
Does anyone know / is anyone able to work out how I can prevent this so that I do the rafactoring operation and the folds remain as they were before please?
Cheers :)
YES! I did it!
My solution was:
Install FastFold (https://github.com/Konfekt/FastFold) [1]
Install vim-stay (https://github.com/kopischke/vim-stay) [2]. I'm not sure if this plugin is 100% necessary for this solution but it seems pretty useful anyway (e.g. persists folds after save, close, and re-open).
Use the recommended settings for vim-stay, i.e. add set viewoptions=cursor,folds,slash,unix
to .vimrc
.
Set the optional FastFold setting let g:fastfold_savehook = 0
by adding it to .vimrc
. This appears to be the crucial step that finally got it to work.
Happy days! Enjoy!
UPDATE: If you change the folds that you have open / closed since you opened the file, you have to save the view (not the file) using :mkview
for those folds to persist after a refactoring [3].
Footnotes:
[1] I use Vundle (https://github.com/VundleVim/Vundle.vim) so for me this was just a case of adding Bundle 'Konfekt/FastFold'
to my .vimrc
, saving, closing, re-opening, and then running :BundleList
followed by :BundleInstall
.
[2] Installation is the same as above but substitute kopischke/vim-stay
for Konfekt/FastFold
.
[3] I found this was easier when mapped to a key, in my case <F9>