Vimrc 文件需要越来越长的时间来重新加载 [英] Vimrc file takes longer and longer to reload

查看:20
本文介绍了Vimrc 文件需要越来越长的时间来重新加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 .vimrc 中有以下内容,以便在保存后进行处理

I have the following in my .vimrc so that it processes after saving

" source as soon as we write the vimrc file
if has("autocmd")
  autocmd bufwritepost .vimrc source $MYVIMRC
endif

然而,我有一个更复杂的文件,似乎保存后发布 vimrc 文件的时间越来越长,我不得不退出 gvim 会话并重新开始.

However, I have a more involved file, and it appears that the time to post the vimrc file after save gets longer and longer and longer to where I have to quit out of my gvim session and start over.

是否有清晰的工作空间"或更好的方法来解决此问题,以便我可以整天保持在单个 gvim 会话中的舒适度?

Is there a 'clear workspace' or a better way to resolve this issue, so that I may stay within the comforts of my single gvim session all day?

推荐答案

每次获取 autocmd 时,都会将其添加到 autocmd 列表中.因此,当您保存时,您可能会多次获取 vimrc,因为每次获取时都会将 autocmd 添加到列表中.(通过执行:au bufwritepost可以看到多次添加了autocmd)

Every time the autocmd is sourced it is added to the autocmd list. So you might be sourcing your vimrc thousands of times when you save because everytime you source you add the autocmd to the list. (You can see that the autocmd is added multiple time by doing :au bufwritepost)

要解决此问题,您只需要将 autocmd 包装在一个 augroup 中,并在加载时清除该组.

To fix this you just need to wrap the autocmd in a augroup and clear the group when it is loaded.

augroup NAME_OF_GROUP
  autocmd!
  autocmd bufwritepost .vimrc source $MYVIMRC
augroup end

autocmd! 从组中删除所有自动命令.

The autocmd! removes all autocmds from the group.

帮助页面阅读:h autocmd-define:h autocmd-groups

这篇关于Vimrc 文件需要越来越长的时间来重新加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆