代码折叠未保存在我的 vimrc 中

发布于 2024-08-19 10:11:18 字数 491 浏览 4 评论 0原文

我将以下代码添加到我的 .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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我爱人 2024-08-26 10:11:18

问题是您的原始 autocmd 行设置为匹配模式 *.*,即包含一些字符、后跟一个点、再跟一些字符的任何文件名。

因此,文件 test.htmlanothertest.css 将被匹配,并且您的命令将运行,但 .vimrc 之前没有任何内容点,将不会被匹配。

解决方案是设置一个与 .vimrc 匹配的 autocmd。您对 ?* 的猜测确实与此匹配(因为它正在查找任何字符,后跟任意数量的其他字符),但您说它会以某种方式影响 MRU。我不知道你的 MRU 使用什么插件,但我猜它会在临时窗口中打开 MRU 列表,其名称与 ?* 模式匹配,并且视图的后续加载以某种方式进行弄乱你的 MRU。

因此,解决方法是使用更具体的内容来匹配 .vimrc:

autocmd BufWinLeave .vimrc mkview
autocmd BufWinEnter .vimrc silent loadview 

这也可能有效,而且更通用:

autocmd BufWinLeave .* mkview
autocmd BufWinEnter .* silent loadview 

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 or anothertest.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:

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 
折戟 2024-08-26 10:11:18

根据 Jays 的评论,这是最优雅的解决方案,我有很多插件并在多个操作系统上运行它,并且刚刚对其进行了测试。

autocmd BufWrite * mkview
autocmd BufRead * silent loadview

它不会破坏 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.

autocmd BufWrite * mkview
autocmd BufRead * silent loadview

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??

不奢求什么 2024-08-26 10:11:18

我有类似的问题。也许您必须创建保存数据的目录。

mkdir -p ~/.vim/view
chmod 0750 ~/.vim ~/.vim/view

i had a similar problem. maybe you have to create the directory which holds the data.

mkdir -p ~/.vim/view
chmod 0750 ~/.vim ~/.vim/view
剑心龙吟 2024-08-26 10:11:18

在 Arch Linux 中使用 Neovim 时,我一直收到错误消息,直到我附加了 !沉默之后(沉默!)。这是我的 ~/.vimrc 条目,

autocmd BufWrite * mkview
autocmd BufRead * silent! loadview

详细信息在这里:

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,

autocmd BufWrite * mkview
autocmd BufRead * silent! loadview

Details here:

https://github.com/neovim/neovim/issues/7442#issuecomment-339752054

冷情 2024-08-26 10:11:18

将其添加到 vimrc 的顶部以确保 viewdir 存在

let &viewdir=expand("$HOME") . "/.bk/.vim/viewdir"
if !isdirectory(expand(&viewdir))|call mkdir(expand(&viewdir), "p", 451)|endif

然后将其添加到您的 autocmds 部分中:

autocmd BufWrite * mkview
autocmd BufNewFile,BufRead * silent loadview

Add this to the top of your vimrc to make sure the viewdir is present

let &viewdir=expand("$HOME") . "/.bk/.vim/viewdir"
if !isdirectory(expand(&viewdir))|call mkdir(expand(&viewdir), "p", 451)|endif

Then this in your autocmds section:

autocmd BufWrite * mkview
autocmd BufNewFile,BufRead * silent loadview
空心↖ 2024-08-26 10:11:18

视图详细信息保存在 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文