5 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 5 years ago
In a more dynamic way, you can use
$MYVIMRC instead of
autocmd! bufwritepost $MYVIMRC source $MYVIMRC
Chris Penner 5 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 2 years ago
I would love to know how to do this withou moving my cursor
Rahul Gupta 1 year ago
Very useful, thanks guys ! For neovim i used this:
autocmd! bufwritepost ~/.vimrc source $MYVIMRC
Because my $MYVIMRC points to ~/.config/nvim/init.vim
source ~/.vimrc internally.
Sérgio Luiz Araújo Silva 1 year ago
"It is recommended to use autocommands in groups, so:
augroup Reload autocmd! autocmd BufWritePost init.vim call ReloadVimrcFunction() augroup END
Sérgio Luiz Araújo Silva 9 months ago
In my case I have placed this autocommand on the file:
Once that "init.vim" is a vim filetype it only sets the mentioned autocommand on vim filetypes. For each filetype we can have a filetype.vim like c.vim and have all the autocommands loaded just if we are editing that filetype.