545
163
Can you edit your .vimrc
file and reload it without having to restart Vim?
545
163
Can you edit your .vimrc
file and reload it without having to restart Vim?
681
If you're editing it, you can reload it with:
:so %
%
stands for current file name (see :h current-file
) and :so
is short for :source
, which reads the content of the specified file and treats it as Vim code.
In general, to re-load the currently active .vimrc, use the following (see Daily Vim):
:so $MYVIMRC
79
Even better, you configure Vim to watch for changes in your .vimrc
and automatically reload the config.
augroup myvimrc
au!
au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END
Source: this answer on SO
Note: this particular method watches for the many variations of Vim config filenames so that it's compatible with GUI Vim, Windows Vim, etc.
2How performant is this method? – Alexej Magura – 2017-09-19T18:37:07.043
I find that use this kind of command sometimes hangs my nvim for a few seconds or longer. – jdhao – 2018-09-29T08:29:45.470
11
" 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:
:messages
)fugitive://
diff)vim-tiny
Of course, the automatic reload will only happen if you edit your vimrc
in vim.
5
An alternative to remembering/typing :so $MYVIMRC
is these mappings. It lets you quickly edit vimrc (ev
) or source vimrc (sv
).
" Quickly open/reload vim
nnoremap <leader>ev :split $MYVIMRC<CR>
nnoremap <leader>sv :source $MYVIMRC<CR>
4Note that if keyboard mappings were already in place, then they will not erased even if they are deleted from the new vimrc – Phani – 2014-10-02T06:58:46.257
2
Have a look at http://stackoverflow.com/questions/803464/how-do-i-source-something-in-my-vimrc-file
– mrucci – 2010-04-17T14:27:37.783Or
:so ~/.vim/gvimrc
or wherever you put it of course – NeilG – 2019-08-20T01:47:10.787Can we somehow fully flush the user config while running vim, THEN load the user config again? – jchook – 2020-02-06T02:21:06.400
38and
:so ~/.vimrc
should work too on unix – Yab – 2011-05-08T18:18:55.0803:so ~/_vimrc works on windows. Of course, I keep my _vimrc in my windows home directory, or else this won't work. To see what Vim considers your home directory, use
:echo expand("~")
. – Daniel Miladinov – 2012-11-30T14:10:07.907