Ubuntu 16.04.6 LTS
Vim 7.4
Setting in ~/.vimrc file
if &cp | set noocp | endif
I’m curious about the function of the phrase
What is &cp and what function is |?
I’m also curious about the function of if…endif
Sorry, I’m a beginner If you give me an answer, it will help me a lot
2
Answers
&cp
— value of Vim optioncp
(:h 41.3
,:h 'cp'
),|
— another command in same command line (:h :bar
),if ... endif
— conditional expression (:h :if
).First, let’s fix that nagging typo:
Now we can talk…
The whole thing is a conditional:
See
:help 41.4
.If you want to save space, you can put a sequence of commands on a single line, separated with
|
:See
:help :bar
.&cp
, or&compatible
, is an expression that evaluates to1
(true in vimscript) if thecompatible
option is set and0
(false) if it is disabled:See
:help 'compatible'
and:help expr-option
The statement between the
:if
and the:else
isset nocp
, which unsetscompatible
:So, that line tells Vim to check if
compatible
is set and, if yes, to unset it.FWIW,
compatible
is automatically unset when Vim encounters avimrc
at an expected location so&cp
is always going to be evaluated to0
in your~/.vimrc
, which, basically, makes that line useless outside of very specific use cases that you shouldn’t encounter if you have to ask that question.