Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a .vimrc, is `set nocompatible` completely useless?

Tags:

vim

Several users in this epic question put the following in the .vimrc:

" Necesary for lots of cool vim things set nocompatible 

But is it really necessary? From the docs:

'compatible' 'cp'     boolean (default on, off when a |vimrc| or |gvimrc| file is found) 

If set nocompatible is going in a .vimrc, that means that a .vimrc file exists, seemingly making it pointless.

like image 731
ClosureCowboy Avatar asked May 01 '11 00:05

ClosureCowboy


People also ask

What does set Nocompatible do vimrc?

If set nocompatible is going in a . vimrc , that means that a . vimrc file exists, seemingly making it pointless.

How do I edit vimrc?

Opening vimrc Using file name completion, you could type :e $M then press Tab until you see the desired variable. If you only want to see the path, type :echo $M then press Tab to see the variable, and press Enter. In gvim, the Edit menu includes "Startup Settings" which will use $MYVIMRC to edit your vimrc file.


2 Answers

If it is the system-wide vimrc, this option won't be off. So, if you're changing the system-wide vimrc and you want it, you need to set it.

From the documentation section *compatible-default* (emphasis mine):

When Vim starts, the 'compatible' option is on. This will be used when Vim starts its initializations. But as soon as a user vimrc file is found, or a vimrc file in the current directory, or the "VIMINIT" environment variable is set, it will be set to 'nocompatible'.

Another difference is that explicitly setting 'nocompatible' overrules calling vim with the -C flag.

In any other scenario, yes, setting 'nocompatible' in your vimrc is a noop.

In the end I think it's just a matter of "better safe than sorry".

like image 172
R. Martinho Fernandes Avatar answered Oct 05 '22 23:10

R. Martinho Fernandes


Many people share their .vimrc files on GitHub and I sometimes will test out settings without replacing my .vimrc file. vim allows me to do this with the -u flag.

vim -u test_vimrc 

From vim ":help nocompatible"

(Note: This doesn't happen for the system-wide vimrc or gvimrc file, nor for a file given with the |-u| argument).

This means that if you share your .vimrc with someone and they use -u flag to load your file, vim won't be configured the same as if the file were named .vimrc and located in your home directory.

like image 28
Chad Skeeters Avatar answered Oct 06 '22 01:10

Chad Skeeters