代码折叠未保存在我的vimrc中 [英] Code folding is not saved in my vimrc
问题描述
我在.vimrc中添加了以下代码:
I added the following code to my .vimrc:
" save and restore folds when a file is closed and re-opened
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview
HTML和CSS文档可以保存并恢复折叠,但是代码折叠没有保存在我的 .vimrc
HTML and CSS documents save and restore their folds but code folding is not being saved in my .vimrc
有什么建议吗?
编辑:
以下代码解决了这个问题:
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview
但是,如果我将其写入,则MRU文件从列表中消失(为什么我必须打开MRU两次才能查看最近的文件列表,为什么?)
but if I write it, the MRU files disappear from my list (and I have to open MRU twice in order to see my list of recent files why?)
推荐答案
问题是您原来的 autocmd
行设置为匹配模式 *。*
,即,任何包含一些字符的文件名,后跟一个点
The problem is that your original autocmd
lines are set to match the pattern *.*
, i.e. any filename which contains some characters, followed by a dot, followed by some more characters.
因此文件 test.html
或 anothertest.css
将被匹配,并且您的命令将运行,但是 .vimrc
(在点之前没有任何内容)将不匹配。
So the file test.html
or anothertest.css
will be matched, and your command will run, but .vimrc
, which has nothing prior to the dot, will not be matched.
解决方案是设置一个与 .vimrc
匹配的自动命令。您对?*
的猜测确实与此相符(因为它正在寻找任何字符,后跟任意数量的其他字符),但是您说它会以某种方式影响MRU。我不知道您要为MRU使用哪个插件,但是我猜想它是一个在临时窗口中打开MRU列表的插件,其名称与?*模式匹配,并且随后以某种方式加载视图
The solution is to set up an autocmd which will match .vimrc
. Your guess of ?*
does match this (because it's looking for any character, followed by any number of other characters), but you say it somehow affects MRUs. I don't know what plugin you're using for your MRUs, but I'm guessing it's one which opens the MRU list in a temporary window with a name that matches the ?* pattern, and the subsequent loading of the view is somehow messing with your MRUs.
因此,解决方法是使用更具体的方式来匹配.vimrc:
Therefore, the fix is to use something a bit more specific to match .vimrc:
autocmd BufWinLeave .vimrc mkview
autocmd BufWinEnter .vimrc silent loadview
这也可能起作用,并且更通用:
It's possible that this will work, too, and is more general:
autocmd BufWinLeave .* mkview
autocmd BufWinEnter .* silent loadview
这篇关于代码折叠未保存在我的vimrc中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!