Question

I wanted to keep all files related to vim in one folder under my $HOME directory, more specifically my gvimrc file. I've moved the original .gvimrc file to $HOME/vim/.gvimrc and created a symlink under my $HOME directory. However, when I run source %, simple functions do not run until I exit and restart the session. For example:

function! EchoSomething()
  if &bg == dark
    echo "bg is dark"
  else
    echo "bg is light"
  endif
endfunction

This should echo the results on the cmdline, but it show nothing when I source my .gvimrc file.

Was it helpful?

Solution

My preferred alternative to a symlink is to add a source directive to an otherwise empty file at $HOME/.gvimrc

So, if you have another .gvimrc at /path/to/it/, instead of creating a symlink, create an empty file at $HOME/.gvimrc and add the line:

source /path/to/it/.gvimrc

OTHER TIPS

  1. gvimrc (with or without a dot and wherever it is located) is not sourced when you use vim in a terminal.

  2. Since 7.4, CLI Vim and GUI Vim look for the classical $HOME/.vimrc and $HOME/.vim/vimrc and GUI Vim also looks look for the classical $HOME/.gvimrc and $HOME/.vim/gvimrc.

    So you can safely drop your symlinks and just rename $HOME/.vim/.gvimrc to $HOME/.vim/gvimrc.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top