kalekundert/vim-coiled-snake

folding stops when viewing same file in two windows

Closed this issue · 8 comments

Using neovim v0.2.2

Steps to reproduce

  1. open two files in vim like nvim file1.py file2.py
  2. use :vsplit to open two windows, both windows should show file1.py
  3. go to the buffer holding file2.py in the window on the left, it should be folded correctly
  4. go to the buffer holding file2.py in the window on the right and everything will be unfolded!

Please let me know if you can reproduce this issue!

Thanks for the report! It seems like a really weird bug, but I can reproduce it. I'll see if I can figure out what's going on, but I don't really have any ideas off the top of my head.

I did notice that if I switch to the right split before loading file2.py initially, then I can go back and load it in the left split without getting the buggy behavior. I don't know if that's meaningful or not.

Quick update:

  1. A slightly easier way to get the bug is to pass same file to nvim twice (this doesn't require switching between windows):
    $ nvim file1.py file1.py
    :vsplit
    :wn
    
  2. The problem is related to the FastFold plugin:
    • Removing plugin is enough to fix the buggy behavior.
    • Inserting or removing a character (in the window without folds) then returning to normal mode is enough to restore the folds. Presumably this triggers FastFold to recalculate the folds.
    • The hotkeys that are supposed to trigger FastFold to recalculate the folds—specifically zuz (which has no other purpose) but also zj, zk, [z, and ]z—do not restore the folds, interestingly.
    • Running :set foldmethod=expr (again, only in the window with the bug) does restore the folds.

Actually, I think Konfekt/FastFold#52 is exactly this issue, and it looks like a fix was pushed 19 days ago. So try pulling the most recent version of FastFold and see if that fixes the problem.

Hmm, I just tried this again after updating FastFold, and then outright removing it (first by commenting out the line in my vimrc that loads the plugin and then by also deleting all the FastFold files in ~/.vim/bundle). In all cases I got the same behavior. Additionally, your method of opening the same file twice did not replicate the bug for me. Perhaps we are seeing different bugs with the same end result?

I'll see if I can't find some other information that's unique to my version of the bug and post it here when/if I find it.

Ugh, I thought for sure that was the problem. Does making edits in the buffer without folds, or :set foldmethod=expr restore the folds for you?

Neither of those things worked. I also updated my neovim to 0.3.1 and have the same issue :/. I'll keep trying stuff as I come up with ideas.

I was able to reproduce the same problem as well on Neovim 0.3.0 and FastFold commit cdd44dcf54dd6900e9699e957ba4b203d3021d1d . However, the problem goes away if I use the vim-stay plugin.

This does seem like it should be related to Konfekt/FastFold#52 as mentioned above but the fix there doesn't fix this issue.