[英]How to correctly reload .vimrc file so it will be equal to restart of vim?
I use MacVim and in my .vimrc file I have map ,V :source $MYVIMRC<CR>
binding that allows me to apply the newest version of .vimrc
in a case it was recently modified. 我使用MacVim,在我的.vimrc文件中,有
map ,V :source $MYVIMRC<CR>
绑定,如果最近被修改,它允许我应用.vimrc
的最新版本。 However I noticed that strange things can happen, relaunch can slow down vim and some plugins can start to conflict after pressing ,V
, when everything works fine if I just close and relaunch MacVim from the scratch. 但是我注意到可能会发生奇怪的事情,重新启动会减慢vim的运行速度,某些插件在按
,V
后会开始发生冲突,如果一切正常,如果我只是关闭并重新启动MacVim的话。
I'd be very thankful if you could give me a hint on the reason of this behavior as I'd like to have a possibility to update .vimrc
file that will completely clear internal vim state and grab new configuration file 如果您能给我提示此行为的原因,我将非常感谢,因为我希望可以更新
.vimrc
文件,以完全清除内部vim状态并获取新的配置文件。
The only viable way to re-apply your config to a pristine Vim is actually to restart it. 将配置重新应用到原始Vim的唯一可行方法实际上是重新启动它。
But the most likely cause of slow downs is the overuse/misuse of autocommands. 但是最慢的原因可能是自动命令的过度使用/滥用。
Autocommands are added without checking for existing ones. 添加自动命令时不检查现有命令。 One consequence is that they tend to pile-up if you don't manage them properly and every individual autocommand corresponding to a specific event is executed when that event is triggered, leading to dreadful slow downs.
结果是,如果您没有正确地管理它们,它们就会堆积起来,并且与特定事件相对应的每个单独的自动命令都会在触发该事件时执行,从而导致可怕的减速。
Here are the two ways you are supposed to use autocommands in your vimrc
: 这是您应该在
vimrc
使用自动命令的两种方式:
Method #1 方法1
" anywhere
augroup nameofthegroup
autocmd!
autocmd EventName pattern commandtoexecute
autocmd AnotherEventName anotherpattern anothercommandtoexecute
augroup END
Method #2 方法#2
" near the top of your vimrc
augroup nameofthegroup
autocmd!
augroup END
" anywhere
autocmd nameofthegroup EventName pattern commandtoexecute
autocmd nameofthegroup AnotherEventName anotherpattern anothercommandtoexecute
The idea is to create a group of autocommands that clears itself whenever it is invoked and thus prevents them from piling-up. 想法是创建一组自动命令,该命令在被调用时会自动清除,从而防止它们堆积。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.