10 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
Chris Penner 10 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 6 years ago
I would love to know how to do this withou moving my cursor
Rahul Gupta 6 years 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.
Sérgio Luiz Araújo Silva 5 years 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 4 years ago
In my case I have placed this autocommand on the file:
~/.config/nvim/after/ftplugin/vim.vim
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.
KabbAmine 10 years ago
In a more dynamic way, you can use
$MYVIMRC
instead of.vimrc
.autocmd! bufwritepost $MYVIMRC source $MYVIMRC