代码折叠未保存在我的 vimrc 中
我将以下代码添加到我的 .vimrc 中:
" save and restore folds when a file is closed and re-opened
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview
HTML 和 CSS 文档保存并恢复其折叠,但代码折叠未保存在我的 .vimrc 中
有什么建议吗?
编辑:
以下代码解决了问题:
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview
但是如果我编写它,MRU 文件就会从我的列表中消失(并且我必须打开 MRU 两次才能看到我的列表最近的文件为什么?)
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 and CSS documents save and restore their folds but code folding is not being saved in my .vimrc
Any suggestions?
EDIT:
The following code solves the problem:
au BufWinLeave ?* mkview
au BufWinEnter ?* silent loadview
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?)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
问题是您的原始
autocmd
行设置为匹配模式*.*
,即包含一些字符、后跟一个点、再跟一些字符的任何文件名。因此,文件
test.html
或anothertest.css
将被匹配,并且您的命令将运行,但.vimrc
之前没有任何内容点,将不会被匹配。解决方案是设置一个与
.vimrc
匹配的 autocmd。您对?*
的猜测确实与此匹配(因为它正在查找任何字符,后跟任意数量的其他字符),但您说它会以某种方式影响 MRU。我不知道你的 MRU 使用什么插件,但我猜它会在临时窗口中打开 MRU 列表,其名称与 ?* 模式匹配,并且视图的后续加载以某种方式进行弄乱你的 MRU。因此,解决方法是使用更具体的内容来匹配 .vimrc:
这也可能有效,而且更通用:
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.So the file
test.html
oranothertest.css
will be matched, and your command will run, but.vimrc
, which has nothing prior to the dot, will not be matched.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.Therefore, the fix is to use something a bit more specific to match .vimrc:
It's possible that this will work, too, and is more general:
根据 Jays 的评论,这是最优雅的解决方案,我有很多插件并在多个操作系统上运行它,并且刚刚对其进行了测试。
它不会破坏 MRU 并使您必须双重查询 MRU
当您 :new 进入空缓冲区时,它不会出错
它也不要求您为您可能使用的每种文件类型创建 FileType 模式。
注意:在“BufNewFile”上使用“loadview”似乎是令 MRU 感到困惑的原因,我认为尝试在空缓冲区上渲染折叠是毫无意义的?
Per Jays comments this is the most elegant solution, I have a LOT of plugins and run it on multiple OSes and have just tested it.
It does not break MRU and make you have to double query MRU
It does not error when you :new into an empty buffer
It also doesn't require you to create FileType patern for every file-type you may possibly use.
NOTE: using "loadview" on "BufNewFile" apears to be what confuses MRU, rather pointless trying to render folds on an empty buffer I would have thought??
我有类似的问题。也许您必须创建保存数据的目录。
i had a similar problem. maybe you have to create the directory which holds the data.
在 Arch Linux 中使用 Neovim 时,我一直收到错误消息,直到我附加了 !沉默之后(沉默!)。这是我的 ~/.vimrc 条目,
详细信息在这里:
https://github。 com/neovim/neovim/issues/7442#issuecomment-339752054
With Neovim in Arch Linux, I was getting error messages until I appended a ! after silent (silent!). Here is my ~/.vimrc entry,
Details here:
https://github.com/neovim/neovim/issues/7442#issuecomment-339752054
将其添加到 vimrc 的顶部以确保 viewdir 存在
然后将其添加到您的 autocmds 部分中:
Add this to the top of your vimrc to make sure the viewdir is present
Then this in your autocmds section:
视图详细信息保存在
vimfiles\view
目录中的视图文件中。为您编辑的每个文件创建一个单独的视图文件。The view details get saved in view file in the
vimfiles\view
directory. A separate view file is created for every file you edit.