It bothers me when I wrote something into .vimrc and I have to close it first and open to get my changes be applied. Is there a way of reload .vimrc in Vim without closing it?

E.g. I've added set nu to ~/.vimrc and I want line numbers to appear for all my windows and buffers.

4 Answers 4


:source ~/.vimrc

Run that from inside vim, that will apply your .vimrc


:source $MYVIMRC


:so %

if currently editing .vimrc

  • 2
    i.e. :source %
    – tafchad
    Commented Jun 13, 2020 at 9:43
  • Underrated answer. Fewer keystrokes; this is prob the one I'll remember Commented Nov 9, 2021 at 1:57

Here's one for posterity. Add the following to your .vimrc:

map <leader>vimrc :tabe ~/.vim/.vimrc<cr>
autocmd bufwritepost .vimrc source $MYVIMRC

The first line means you can open your vimrc from any vim buffer by typing your leader, then writing "vimrc." For example, my leader is set to comma, so if I'm in edit mode and I type ",vimrc" it opens my vimrc in a new tab.

The second line automatically sources the changes to your vimrc when you save and close it. It's magic.

  • 3
    Ideally wouldnt you map <leader>vimrc :tabe $MYVIMRC<cr> to match the autocmd?
    – Nick Bisby
    Commented Sep 3, 2014 at 15:38
  • @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
    Commented Sep 3, 2014 at 16:45
  • 2
    Alternatively you could use a symbolic link to your actual .vimrc file instead of having it be a stub.
    – Spoike
    Commented Apr 19, 2016 at 12:14
  • How can I reload vimrc without changing the position of my cursor? Commented Dec 17, 2017 at 20:35
  • The autocmd is going to register a new additional autocmd every time you source the vimrc
    – CervEd
    Commented Mar 19, 2023 at 9:42
" 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.


  • 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.

  • This is great, but when I have the window maximized (gvim), it resizes it to a windowed state. Any idea how to solve that?
    – typo
    Commented Mar 19, 2020 at 4:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .