Is it possible to apply vim configurations without restarting?

后端 未结 5 1179
南笙
南笙 2020-12-12 19:45

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

5条回答
  •  感动是毒
    2020-12-12 20:05

    " Quickly edit/reload this configuration file
    nnoremap gev :e $MYVIMRC
    nnoremap gsv :so $MYVIMRC
    

    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.

提交回复
热议问题