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
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
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 (
: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 winminwidth=1 when using vertical splits will make current window automatically fill width of Vim's screen. . . )