Auto Source vimrc When Saved
If you find yourself always executing :so
after every vimrc
change, put this
in your .vimrc
.
autocmd! bufwritepost .vimrc source %
This causes Vim to automatically source and apply your changes to your vimrc
when
the buffer is saved.
Improvements
One
It will be better option to use variable, since your .vimrc
file may be
different: For instance if you use NeoVim your rc
file is init.vim
.
" Automatically source vimrc on save.
autocmd! bufwritepost $MYVIMRC source $MYVIMRC
Two
I want to see a confirmation from Vim after my file sourced to ensure everything is OK. In order to make this happen you can use below snippet:
autocmd! BufWritePost $MYVIMRC source $MYVIMRC | echom "Reloaded $NVIMRC"
All done!
Subscribe
Read Related