简体   繁体   中英

Set if &cp | set noocp | endif in the ~/.vimrc file

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

First, let's fix that nagging typo:

if &cp | set nocp | endif

Now we can talk…

The whole thing is a conditional:

if <expression that evaluates to 1 ("true")>
  <do something>
endif

See :help 41.4 .

If you want to save space, you can put a sequence of commands on a single line, separated with | :

if <expression that evaluates to 1> | <do something> | endif

See :help :bar .

&cp , or &compatible , is an expression that evaluates to 1 (true in vimscript) if the compatible option is set and 0 (false) if it is disabled:

if &cp | <do something> | endif

See :help 'compatible' and :help expr-option

The statement between the :if and the :else is set nocp , which unsets compatible :

if &cp | set nocp | endif

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 a vimrc at an expected location so &cp is always going to be evaluated to 0 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.

&cp -- value of Vim option cp ( :h 41.3 , :h 'cp' ), | -- another command in same command line ( :h :bar ), if ... endif -- conditional expression ( :h :if ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM