Second user vimrc file usage on vim running on Mac os X 10.8.5 (Mountain Lion)

5

1

I am using MacVim:

:version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 10 2013 17:49:20)
MacOS X (unix) version

I've executed :version in vim (to check what patches I had installed) and noticed the following two lines part of the output:

 user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"

What is the 2nd user for, and how would you use it?

I've found and read this question:https://apple.stackexchange.com/q/34996/10733,

but the answer shows how to integrate the ~/.vim/vimrc into .vimrc.

I also did the following search in google which did not yield anything interesting: 2nd user in vim and ~/.vim/vimrc, and how to use ~/.vim/vimrc

Deesbek

Posted 2013-10-16T13:27:53.320

Reputation: 303

Would you mind if we migrate this to SuperUser? You might get better answers there. – nohillside – 2013-10-17T18:06:38.780

Of course no, problems. I should have put it there myself. I was going to add a bounty on it when the time allowed. – Deesbek – 2013-10-17T18:07:54.210

1This is something new in vim 7.4 where they have a different (additional) default vimrc location. What version of vim are you using (as the default one on mac should not have that output) – FDinoff – 2013-10-17T20:02:53.230

Answers

6

The "2nd user vimrc file" is a recent addition to Vim, appearing maybe in very late versions of Vim 7.3 but certainly by Vim 7.4.

Some users requested that second location for their personal vimrc file so that they could keep all their Vim configuration files in one directory: ~/.vim on Unix or ~/vimfiles on Windows.

As it says in :help vimrc,

The files are searched in the order specified above and only the first one that is found is read.

So, if you have both ~/.vimrc and ~/.vim/vimrc files, only ~/.vimrc will be used. Most users use either one or the other, but not both.

garyjohn

Posted 2013-10-16T13:27:53.320

Reputation: 29 085

I am in the process of downloading and reading the code. But from what you wrote above @Vucars answer is not correct? – Deesbek – 2013-10-17T22:48:04.293

Yes, Vucar's answer is not correct regarding both ~/.vimrc and ~/.vim/vimrc being read if both are present. Vucar may be confused between those files and the system vimrc. – garyjohn – 2013-10-17T23:22:45.117

@Deesbek: You're right, I didn't read the code carefully enough. It does indeed pick the first of all those files it finds. I'll edit my answer as soon as I've got some time to do so. – Vucar Timnärakrul – 2013-10-18T15:10:28.553

1

I've taken a look through the code which deals with the output of :version and the various places from whence the .vimrc-file is taken.

Depending on which operating system is used, initialisation files (such as .vimrc) are sought in a number of places. For some operating systems (such as Amiga and most likely Mac as well), more than one directory is examined; there may be up to four different places, which in turn would give you:

  • user vimrc file;
  • 2nd user vimrc file;
  • 3rd user vimrc file and
  • 4th user vimrc file.

(For those interested, the interesting part is in version.c around line 1184.)

As far as I understand from the rest of the code, each of those files is sourced in the order above, stopping as soon as one of those paths does not exist (cf. main.c around line 2993).

So in your particular case, vim would first try to read $HOME/.vimrc. If it exists, it is sourced, and vim looks for ~/.vim/vimrc. If it exists, it is read as well.

You can verify this by putting some commands in either file which produce some output, for example echo "something" into either of the vimrc files.

Vucar Timnärakrul

Posted 2013-10-16T13:27:53.320

Reputation: 671