pythonvimfoldingpython-moderope

How do I prevent automatic re-folding of python code after refactoring using vim with python-mode / rope and SimpylFold


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 :)


Solution

  • YES! I did it!

    My solution was:

    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>