Mars
Mars

Reputation: 8854

Inconsistent initialization

MacVim 8.0:

If there is no .vimrc file, set shows:

:set
--- Options ---
  autoindent          scroll=18           ttymouse=xterm2
  helplang=en         showmatch           wrapmargin=10
  langmenu=none       ttyfast           nowrapscan
  backspace=indent,eol,start
  fileencodings=ucs-bom,utf-8,default,latin1
  pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python
  pythonhome=/usr/local/Frameworks/Python.framework/Versions/2.7

If I create an empty .vimrc file, set shows:

set
--- Options ---
  helplang=en         scroll=18           ttymouse=xterm2
  langmenu=none       ttyfast
  backspace=indent,eol,start
  fileencodings=ucs-bom,utf-8,default,latin1
  pythondll=/usr/local/Frameworks/Python.framework/Versions/2.7/Python
  pythonhome=/usr/local/Frameworks/Python.framework/Versions/2.7

This differs from the first case in that autoindent, showmatch, and wrapscan are missing. Why is there a difference? These options do not seem to be set in /Applications/MacVim.app/Contents/Resources/vim/vimrc.

Starting vim with -u file is supposed to use file as the startup file. So if I remove the empty .vimrc--so now I have no .vimrc--and use -u emptyfile, where emptyfile is an empty file, I would expect that set would show what is listed immediately above. However, set shows something very different:

:set
--- Options ---
  helplang=en         scroll=18           ttyfast             ttymouse=xterm
  fileencodings=ucs-bom,utf-8,default,latin1
  iskeyword=@,48-57,_,192-255

Why is this different from the previous case?

(Why do I care? Because I'm trying to figure out why an initialization file executes properly when it's .vimrc, but not when I run it with -u.)

Upvotes: 1

Views: 121

Answers (2)

romainl
romainl

Reputation: 196751

Without a vimrc at any of the expected locations, Vim sources:

$VIM/vimrc
$VIMRUNTIME/defaults.vim
...

This is new in Vim 8.0. Before that version, Vim would only source $VIM/vimrc in this scenario. The reasoning behind that new feature was allegedly to provide more useful defaults to infrequent users without asking them to write their own vimrc.

See :help defaults.vim.


With a vimrc at one of the expected locations (assuming ~/.vimrc but it can be ~/.vim/vimrc), Vim sources:

$VIM/vimrc
$HOME/.vimrc
...

This is the optimal scenario for frequent users, experienced or not: you get the basic behavior plus all your fancy stuff.


When pointing Vim to a specific vimrc with -u, Vim only sources that specific vimrc.

This is the absolutist scenario that gives you complete control over Vim's settings. I wouldn't recommend it to inexperienced users.

Upvotes: 4

Mars
Mars

Reputation: 8854

I have found part of the answer. (I'll post it here for anyone with a similar question, but I don't expect upvotes for either the question or the answer.)

help initialization says, among other things:

If Vim was started with "-u filename", the file "filename" is used. All following initializations until 4. are skipped. $MYVIMRC is not set.

Most of what is between that point and 4. was not relevant to my situation; these are steps that occur only in special circumstances. However, one item between that point and 4. is:

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.

So the system initialization file is not run when -u is used. (This still doesn't fully answer my first question, which mentions the system initialization file on my system.)

Upvotes: 0

Related Questions