Abrir una nueva pestaña deshace el plegado de código en Vim

I have an HTML file with the CSS in the head. Usually I open the file in 2 tabs, so I can switch between the HTML and CSS easily, but I would also like to fold most of the code (especially the font-face declarations.) Unfortunately, whenever I open a second tab, every single fold is undone.

I can re-fold everything just fine afterwards, but if I open another tab it's all undone again.

I have code folding set up like this in my .vimrc:

 set foldmethod=indent " fold based on indent                          
 set nofoldenable " don't fold by default                            
 set foldlevel=1 " only close/open one foldlevel at a time             
 au BufWinLeave * silent! mkview " save view when closing buffer       
 au BufWinEnter * silent! loadview " load view when opening buffer

preguntado el 30 de enero de 12 a las 19:01

2 Respuestas

First at all it's necessary to know that tabs are not the same thing that buffers. There are a lot a places where this is explained. You need to put this in your ".vimrc" file:

autocmd TabLeave * mkview

autocmd TabEnter * silent loadview

respondido 03 nov., 20:08

Trata de hacerlo :mkview in original buffer than move to same buffer in different tab and do :loadview. This should make the folds the same, which indicates that BufWinLeave and BufWinEnter are not the events you want. . . . Maybe it's also because foldenable is window-specific, in which case you also need to enable folds in the window on the new tab. . .

Also, you don't even need to bother with the mkview/loadview stuff if you just split (:split or :vsplit) the window in the current tab. That should give you two views of the same buffer with same fold setups. Once split the folds in each window will work independently. (:set winwidth=999; :set winminwidth=1 when using vertical splits will make current window automatically fill width of Vim's screen. . . )

Respondido el 31 de enero de 12 a las 04:01

Splitting the current window is a solution, but I usually work with a browser open and taking up half the screen. Tabs let me maximize the screen space for each view. Using mkview/loadview manually does seem to work, although I'd hate to have to type all that out every time I open a tab. Is there another pair of events that replace BufWinEnter/BufWinLeave in my vimrc? - Jordan Acosta

I'm not sure, but I think you could leave BufWinEnter as is and change the mkview trabajar con WinLeave event. Seems like issue could also be that nofoldenable is your default, not sure if loadview automatically changes that or not, but you have to have foldenable set to have folds. - Herbert Sitz

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.