-1

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.

Brandon Mercer
  • 403
  • 1
  • 4
  • 10
  • Do you use Vim 7.4 or another version? Why `$HOME/vim` and not `$HOME/.vim`? – romainl Oct 22 '13 at 12:06
  • That snippet you've posted just defines the function; what's missing is the function _invocation_ with `:call`?! – Ingo Karkat Oct 22 '13 at 12:08
  • I know how to :call the function. However When I do, there is no output on the cmdline. – Brandon Mercer Oct 22 '13 at 12:18
  • @romainl it's vim 7.4, and it is in $HOME/.vim (forgot to add "."). I have reason to believe that it is because I'm using gui version. The script above seems to work in the terminal just fine before actually starting the editor. – Brandon Mercer Oct 22 '13 at 12:24
  • Why should that work in the terminal? There, a `.gvimrc` isn't even invoked?! Your sketchy information makes it hard to troubleshoot. Also, please try setting a marker variable instead of `:echo`; there's less risk of overlooking it, and you don't actually want to echo during startup, do you? – Ingo Karkat Oct 22 '13 at 12:27
  • Rename `$HOME/.vim/.gvimrc` to `$HOME/.vim/gvimrc` and remove your symlink. Also, `.gvimrc` is for GUI Vim. – romainl Oct 22 '13 at 12:33
  • @IngoKarkat No This is just a random example script. I just was just using it as an example. – Brandon Mercer Oct 22 '13 at 12:55

2 Answers2

1

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
asfallows
  • 5,998
  • 6
  • 29
  • 48
0
  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.

Community
  • 1
  • 1
romainl
  • 186,200
  • 21
  • 280
  • 313