Auto-source vimrc when saved

7 Points

Chris Penner Chris Penner

4 years ago

This causes vim to automatically re-source and apply changes to your vimrc when the buffer is saved. Really handy when testing new mappings (or adding new snippets!).

" Automatically source vimrc on save.
autocmd! bufwritepost $MYVIMRC source $MYVIMRC


KabbAmine 4 years ago

In a more dynamic way, you can use $MYVIMRC instead of .vimrc.

autocmd! bufwritepost $MYVIMRC source $MYVIMRC
Chris Penner

Chris Penner 4 years ago

Good point, I made it halfway and apparently just didn't complete the thought. Swapped it out.

Sérgio Luiz Araújo Silva

Sérgio Luiz Araújo Silva 1 year ago

I would love to know how to do this withou moving my cursor

Rahul Gupta

Rahul Gupta 2 months ago

Very useful, thanks guys ! For neovim i used this:

autocmd! bufwritepost ~/.vimrc source $MYVIMRC

Because my $MYVIMRC points to ~/.config/nvim/init.vim which contains source ~/.vimrc internally.