What determines the very first file that Vim will load on startup?

17 views
Skip to first unread message

DwigtArmyOfChampions

unread,
Jan 17, 2020, 8:10:37 AM1/17/20
to vim_use
I am using Vim 7.4. I have a file /etc/vimrc, but when I vim a file and run the :scriptnames command, the very first file loaded is ~/.vimrc. 

On another Linux machine I also have Vim 7.4 installed, and when run the vim command and then run :scriptnames, that loads /etc/vimrc.

Where is this loading order determined? 

Ottavio Caruso

unread,
Jan 17, 2020, 9:57:16 AM1/17/20
to vim...@googlegroups.com
I have this is my help file:

system-vimrc
b. For Unix, MS-DOS, MS-Windows, OS/2, VMS, Macintosh, RISC-OS and Amiga
the system vimrc file is read for initializations. The path of this
file is shown with the ":version" command. Mostly it's "$VIM/vimrc".
Note that this file is ALWAYS read in 'compatible' mode, since the
automatic resetting of 'compatible' is only done later. Add a ":set
nocp" command if you like.
For the Macintosh the $VIMRUNTIME/macmap.vim is read.

VIMINIT .vimrc _vimrc EXINIT .exrc _exrc $MYVIMRC



$ vim --version
[...]
system vimrc file: "/usr/pkg/etc/vimrc"
user vimrc file: "$HOME/.vimrc"
2nd user vimrc file: "~/.vim/vimrc"
user exrc file: "$HOME/.exrc"
defaults file: "$VIMRUNTIME/defaults.vim"
fall-back for $VIM: "/usr/pkg/share/vim"

echo $VIM
/usr/pkg/share/vim



--
Ottavio Caruso

Tony Mechelynck

unread,
Jan 17, 2020, 1:21:31 PM1/17/20
to vim_use
The first file sourced at startup is the "system vimrc" — if it
exists. Its default name is $VIM/vimrc (with no initial period to the
filename) but the path can be modified at compile time; on most
versions of Vim distributed as part of Linux distributions the system
vimrc, if it exists, is at /etc/vimrc. Its path for a given Vim
executable can be found near the middle of the output of the :version
command. If you have different Vim executables on the same machine,
looking for their system vimrc scripts at different places, and you
want them to use the same script (for all users — all login names — on
that system) you can put at one of these locations a symlink to the
other one. The recommended procedure is to use one ~/.vimrc (see
below) per user; if a single person can login under more than one
username it is possible to maintain one .vimrc and set symlinks for
the other usernames'.

If there is no "vimrc" file where Vim looks for the system vimrc, that
is no error, and Vim just goes on to the next startup step, which is
looking in several places for your user vimrc. Again, not finding it
is no error, and if it is not found, modern versions of Vim (starting
at Vim 8.0) source $VIMRUNTIME/defaults.vim, unless they have been
specifically ordered not to load it, e.g. by having -u NONE on the
command-line.

For details, see ":help startup" and in particular its steps b (:help
system-vimrc) and c (:help .vimrc).

BTW, Vim 7.4 is getting a little long in the teeth: the current
version as of this writing is 8.2.124.

Best regards,
Tony.
Reply all
Reply to author
Forward
0 new messages