本文主要是介绍Auto-Reload Your Vimrc,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
本文转载至:http://www.bestofvim.com/tip/auto-reload-your-vimrc/
If you're going to master Vim, you're going to spend some time tweaking & tailoring your.vimrc
file. And when you're doing that you'll want to see the effects of any changes as quickly as possible.
It's easy to get Vim to reload the .vimrc
file whenever it changes. Just add this to your.vimrc
file:
augroup reload_vimrc " {autocmd!autocmd BufWritePost $MYVIMRC source $MYVIMRC
augroup END " }
Save, then try it out. Put set number
at the bottom of your .vimrc
& save. Then change it to set nonumber
and save again. Line numbering should pop in an out. Instant reloading.
Breakdown
Let's take a look at what's happening. The bulk of the work's done by the line:
autocmd BufWritePost $MYVIMRC source $MYVIMRC
$MYVIMRC
is the platform-independent location of your .vimrc
file. So this command says that whenever that file is written, source (reload) it immediately afterwards.
The rest of the code, the wrapping, is a pattern you'll see a lot in .vimrc
files:
augroup somename " {autocmd!...
augroup END " }
This is housekeeping. Putting the commands in a group, and starting with autocmd!
clears out any previous autocommands Vim has registered for that group. If we didn't do this, Vim would append a new autocommand every time we wrote the .vimrc
file. Pretty quickly we'd have dozens of source $MYVIMRC
commands queued up for every single write.
See :help $MYVIMRC
, :help source
and especially :help autocmd
for more.
Plus: Steve Losh's excellent Learn Vimscript The Hard Way has a great explanation of how autocommand groups work.
这篇关于Auto-Reload Your Vimrc的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!