Function for source .vimrc and .gvimrc

I usually use GVim, but most of my configuration is done via .vimrc (e.g. key mapping) because I want them in vim and gvim. So when I edit vimrc and then send it from gvim, after that I need to release my .gvimrc to return my color memory (since it is only gvim). I tried to write a function for this and ran into the problems described in the comments below:

function ReloadConfigs()
    :source ~/.vimrc
    if has("gui_running")
        :source ~/.gvimrc
    endif
endfunction
command! Recfg call ReloadConfigs()
" error: function already exists, add ! to replace it

function! ReloadConfigs()
    :source ~/.vimrc
    if has("gui_running")
        :source ~/.gvimrc
    endif
endfunction
command! Recfg call ReloadConfigs()
" error: cannot replace function, it is in use

Is it possible to do something like this? Or, since my .gvimrc has only a few lines, should I just put its contents in a block if has("gui_running")?

+5
source share
2 answers

- .vimrc. , , , :source .vimrc , . :

if !exists("*ReloadConfigs")
  function ReloadConfigs()
      :source ~/.vimrc
      if has("gui_running")
          :source ~/.gvimrc
      endif
  endfunction
  command! Recfg call ReloadConfigs()
endif

, , .

+14

, , .vimrc, gvim, if !has("gui_running").

, , , :

autocmd BufWritePre .gvimrc,.vimrc source <amatch>

, , , . :source $MYVIMRC :source $MYGVIMRC.

+3

All Articles