" Quickly edit/reload this configuration file
nnoremap gev :e $MYVIMRC<CR>
nnoremap gsv :so $MYVIMRC<CR>
To automatically reload upon save, add the following to your $MYVIMRC
:
if has ('autocmd') " Remain compatible with earlier versions
augroup vimrc " Source vim configuration upon save
autocmd! BufWritePost $MYVIMRC source % | echom "Reloaded " . $MYVIMRC | redraw
autocmd! BufWritePost $MYGVIMRC if has('gui_running') | so % | echom "Reloaded " . $MYGVIMRC | endif | redraw
augroup END
endif " has autocmd
and then for the last time, type:
:so %
The next time you save your vimrc
, it will be automatically reloaded.
Features:
- Tells the user what has happened (also logging to
:messages
)
- Handles various names for the configuration files
- Ensures that it wil only match the actual configuration file (ignores copies in other directories, or a
fugitive://
diff)
- Won't generate an error if using
vim-tiny
Of course, the automatic reload will only happen if you edit your vimrc
in vim.
1Ideally wouldnt you
map <leader>vimrc :tabe $MYVIMRC<cr>
to match the autocmd? – Nick Bisby – 2014-09-03T15:38:16.897@NickBisby For me
~/.vimrc
is just a stub that sources~/.vim/.vimrc
so that I can keep everything under source control. For most people you are correct, it would be:tabe $MYVIMRC<cr>
. – Dean – 2014-09-03T16:45:20.6731Alternatively you could use a symbolic link to your actual .vimrc file instead of having it be a stub. – Spoike – 2016-04-19T12:14:50.670
How can I reload vimrc without changing the position of my cursor? – SergioAraujo – 2017-12-17T20:35:43.453