Quantcast

Folding disapear when reopening the same file in a new window

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Folding disapear when reopening the same file in a new window

aleCodd
I find the filding feature too volatile.

It disapears and expands way too often.

What bothers me the most, is when I fold manually, let's say, and reopen the same file in another window or another tab....what happens is that the folding in the first file is gone..

I tried to manually set mkview...did not help

I even tried to do the autocmd suggested in vim manual, so I copied the 2 lines of:

    Au BufWinLeave *.c mkview
    Au BufWinEnter *.c loadview

And still doesn't help.

So any suggestion to make the fold feature more controllable...because as for now..I feel like it decides on its own when to keep or get rid of the folding without any consistent and documented mannar
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Folding disapear when reopening the same file in a new window

Ben Fritz
On Tuesday, March 18, 2014 12:04:16 AM UTC-5, ale wrote:
> I find the filding feature too volatile.
>
>
>
> It disapears and expands way too often.
>
>

If your problem is during insert mode, here is a solution for most cases:

http://vim.wikia.com/wiki/Keep_folds_closed_while_inserting_text

>
> What bothers me the most, is when I fold manually, let's say, and reopen the
>
> same file in another window or another tab....what happens is that the
>
> folding in the first file is gone..
>

That is because folding is local to a window. Creating another window or tab will create a brand new set of folds for you. This is a FEATURE that lets you have multiple different views on a given file.

Actually re-reading that, you said the "folding in the first file is gone". Does that mean that opening a new window messes up folding in the first window? Or that the new window does not inherit the folding from the first window? I answered assuming the former. The latter should not be happening.

However, if you are using syntax folding, and insert some text which defines a fold in one window, that can mess up folding in other windows. That is one of the cases where the link I gave above doesn't help as much.

>
>
> I tried to manually set mkview...did not help
>
>

Did you then manually load the view? I am not perfectly clear from the help, but it may be the case that unless you specify a specific file name or view number, a new number will be used instead of overwriting an old one to allow multiple views on the same file. The help does say 'The combination of ":mkview" and ":loadview" can be used to store up to ten different views of a file.'

>
> I even tried to do the autocmd suggested in vim manual, so I copied the 2
>
> lines of:
>
>
>
>     Au BufWinLeave *.c mkview
>
>     Au BufWinEnter *.c loadview
>
>
>
> And still doesn't help.
>

The BufWinEnter autocmd will only fire if the file is not already visible in a window somewhere. In your case you are opening a new window.

BufWinLeave likewise only fires if this is the very last window on the file.

These autocmds are indended for saving/restoring a SINGLE view on the file between separate edit sessions. You are trying to lock multiple views to have a single set of folds in one edit session, which is a different problem altogether.

>
>
> So any suggestion to make the fold feature more controllable...because as
>
> for now..I feel like it decides on its own when to keep or get rid of the
>
> folding without any consistent and documented mannar
>

Consistent manner: any new window gets its own set of folds that updates independently of the other windows. This includes automatic updates for buffer content changes, even if you don't want those automatic updates.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Folding disapear when reopening the same file in a new window

aleCodd
Thanks so much for your detailed answer.

I still strugle with the folding disappearing from the first window or tab when doing the auto commands....it seems that the mkview on the new window has an impact on any previous view of the file...at least I tried without specifying a number arg to mkview...

As fir now I settled on doing manually mkview when im happy with some folding setting and added to vimrc only the autocmd to loadview...NOT the mkview...

I still had to play around with the events firing this cmd...and ended up adding for all a bunch of them like tabenter tableave winenter and bufread..im not sure what is the right one for my habit of opening multiple tabs for the same file...but hey...this is the configuration that seems to work so far

But I appreciate now what u said...that any autocmd that will mkview on a file...will make a fresh new view for the new buffer and so effectively ruin it for the next loadview cmd that may be fired when u switch back to the old window..or any ather event...

Thanks...
Loading...