Folds deleted when opening new split
achalddave opened this issue · 5 comments
When I open one file with foldmethod=syntax in two splits in a single pane, I find that "re-opening" one of the splits causes the folds in the other split to get deleted.
So, for example, suppose I have two splits as follows, with *
indicating the active split.
foo.c* | foo.c
Now, I run :e
in the left (active) split, and the folds in the right split are all deleted. i.e., I end up with an unfolded buffer in the right split. I would expect the folds to stay in both of the splits. Is this a bug, or is there a configuration option I'm missing?
Thank you for pointing this out!
There is a commit that should fix this. Albeit, perhaps to the detriment of slowing Vim down by unnecessarily recomputing folds when the buffer was not altered. Please check whether performance is affected.
This works! I don't see any significant slow down, although given that there are a number of other plugins that get run when I open a file, I may be failing to notice a slowdown that others with leaner configs may notice.
One nice feature would be if the open/closed state of the folds were maintained in one split when the same file is opened in another split. I'm not sure how viable this is...
I'm not sure how viable this is...
Does the vim-stay
plug-in mitigate the issue?
Perhaps one could save the window state by :mview
It should be viable, but I will not look into it. Pull requests are welcome!
Unfortunately, vim-stay causes a different weirder issue.
Say I have two splits, left
and right
, and I close all folds in both windows. Now, I open a fold (call it A
) in left
, switch to right
, and re-open the file with :e<CR>
. What I would expect is that the open fold in left
stays open, and all the folds in right
remain closed.
Instead, fold A
in left
is closed, and the same fold A
in right is opened. This is probably because when I re-opened the file in right
, vim-stay
tried to "retain" the view from the file that's opened in the left split.
At any rate, I'm not too bothered with folds opening/closing when I re-open the file in a different split, as long as the folds do stay alive. Perhaps one day someone else will be bothered enough and look into a fix for this separate issue, either through FastFold or vim-stay :) Thanks for the help!
Thank you for leaving it as it is, because the whole construction of recomputing folds is shaky. In fact, there is no such command to recompute folds; there is :normal! zx
, but that also closes all folds but the one at the cursor position. For some reason, windo setlocal foldmethod=...
triggers a recomputation, and this plug-in relies thereon. Apparently this causes all kinds of side effects. There is the option to save folds, call :normal! zx
and load folds, but that is just clumsy.
If someone understands what is going on, rather than me trying to holds these entangled autocmds together, his help would be most welcome.