Is it possible to apply vim configurations without restarting?

Vim

Vim Problem Overview


I want to edit .vimrc file from Vim and apply them without restarting Vim.

Vim Solutions


Solution 1 - Vim

Yes, just use the :so % command while editing your .vimrc.

If you want vim to auto-reload your configuration, you must add the following commands :

augroup myvimrchooks
    au!
    autocmd bufwritepost .vimrc source $MYVIMRC
augroup END

the grouping of autocommand is here to avoid "exponential" reloading if you save several times your configuration.

Solution 2 - Vim

Here's a more cross-platform compatible version if you run on Mac/Windows/Linux and gvimrc:

augroup myvimrc
	au!
	au BufWritePost .vimrc,_vimrc,vimrc,.gvimrc,_gvimrc,gvimrc so $MYVIMRC | if has('gui_running') | so $MYGVIMRC | endif
augroup END

The autocmd watches all potential *vimrc files and when one changes, it reloads the vimrc file followed by gvimrc if the GUI is running.

Solution 3 - Vim

source your vimrc file :source ~/.vimrc

Solution 4 - Vim

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

Solution 5 - Vim

> autocmd! bufwritepost _vimrc source %

this will automatic reload all config in _vimrc file when you save

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Question0xdeadbeefView Question on Stackoverflow
Solution 1 - VimRaoul SupercopterView Answer on Stackoverflow
Solution 2 - VimmatpieView Answer on Stackoverflow
Solution 3 - VimshingaraView Answer on Stackoverflow
Solution 4 - VimTom HaleView Answer on Stackoverflow
Solution 5 - VimJamesView Answer on Stackoverflow