How to reload .vimrc file without restarting vim on Linux/Unix

See all VI / Vim text editor related FAQs/HowTos
I am a new vim text editor user. I usually load ~/.vimrc using :vs ~/.vimrc for configuration. Once edited my ~/.vimrc file I need to reload it without having to quit Vim session. How do I edit my ~/.vimrc file and reload it without having to restart Vim on Linux or Unix-like system?

Vim is free and open source text editor that is upwards compatible to Vi. It can be used to edit all kinds of good old text. It is especially useful for editing programs written in C/Perl/Python. One can use it for editing Linux/Unix configuration files. ~/.vimrc is your personal Vim initializations and customization file.
Tutorial details
Difficulty level Easy
Root privileges No
Requirements Linux terminal
Category Text editor
OS compatibility BSD Linux macOS Unix WSL
Est. reading time 2 minutes

How to reload .vimrc file without restarting vim session

The procedure to reload .vimrc in Vim without restart:

  1. Start vim text editor by typing: vim filename
  2. Load vim config file by typing vim command: Esc followed by :vs ~/.vimrc
  3. Add customization like:
    filetype indent plugin on
    set number
    syntax on
  4. Use :wq to save a file and exit from ~/.vimrc window.
  5. Reload ~/.vimrc file by typing any one of the following command:
    :so $MYVIMRC
    :source ~/.vimrc
How to reload .vimrc file without restarting vim

Fig.01: Editing ~/.vimrc and reloading it when needed without quitting vim so that you can continue editing program

The :so[urce]! {file} vim command read vim configfileor ommands from given file such as ~/.vimrc. These are commands that are executed from Normal mode, like you type them. When used after :global, :argdo, :windo, :bufdo, in a loop or when another command follows the display won’t be updated while executing the commands.

How to may keys for edit and reload ~/.vimrc

Append the following in your ~/.vimrc file

" Edit vimr configuration file
nnoremap confe :e $MYVIMRC<CR>
" Reload vims configuration file
nnoremap confr :source $MYVIMRC<CR>

Now just press Esc followed by confe to edit ~/.vimrc file. To reload type Esc followed by confr. Some people like to use the <Leader> key in a .vimrc file. So above mapping becomes:

" Edit vimr configuration file
nnoremap <Leader>ve :e $MYVIMRC<CR>
" " Reload vimr configuration file
nnoremap <Leader>vr :source $MYVIMRC<CR>

The <Leader> key is mapped to \ by default. So you just press \ followed by ve to edit the file. To reload the ~/vimrc file you press \ followed by vr
And there you have it, you just reload .vimrc file without restarting vim ever.

This entry is 4 of 4 in the Exit From Linux and Unix "app" Tutorial series. Keep reading the rest of the series:
  1. How To Exit From top Command In Linux / Unix / BSD / OS X
  2. How To Exit Vim Text Editor Command
  3. Vi / Vim: Save And Quit The Editor Command
  4. How to reload .vimrc file without restarting vim on Linux/Unix

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

5 comments… add one
  • Jim Apr 25, 2022 @ 18:47

    I use Ubuntu and Neovim.
    Now i have a big problem and nothing works for me.
    i use this one: /home/jim/.config/nvim/.init.vim

    in this file i test it with:

    set number

    When i use : “:so %”
    the number works fine for me
    when i start nvim new or a file (*.py) nothing … no numbers …
    So whats going on with this fucking Vim?

    • 🛡️ Vivek Gite (Author and Admin) Vivek Gite Apr 25, 2022 @ 19:06


      File name should be ~/.config/nvim/init.vim .i.e.

  • Lebanov May 19, 2024 @ 8:22

    I think I found a typography right below the `Fig.1`.

  • Joe Klemmer May 19, 2024 @ 11:31

    Wouldn’t the sequence for reloading the file be better done as:

    1) vim ~/.vimrc
    2) Add customizations
    3) :w
    4) :so %

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.