1

我有一个带有 CSS 的 HTML 文件。通常我在 2 个选项卡中打开文件,所以我可以轻松地在 HTML 和 CSS 之间切换,但我也想折叠大部分代码(尤其是字体声明)。不幸的是,每当我打开第二个选项卡时,每个单折被撤消。

之后我可以很好地重新折叠所有内容,但如果我打开另一个选项卡,一切都会再次撤消。

我在我的 .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
4

2 回答 2

1

首先,有必要知道选项卡与缓冲区不同。有很多地方可以解释这一点。你需要把它放在你的“.vimrc”文件中:

autocmd TabLeave * mkview

autocmd TabEnter *静默加载视图

于 2020-11-02T00:45:16.937 回答
0

Try doing :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. . . )

于 2012-01-30T20:52:56.810 回答