简体   繁体   English

设置 if &cp | 设置 noocp | ~/.vimrc 文件中的 endif

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

Ubuntu 16.04.6 LTS Vim 7.4 Ubuntu 16.04.6 LTS Vim 7.4

Setting in ~/.vimrc file在 ~/.vimrc 文件中设置

if &cp | set noocp | endif

I'm curious about the function of the phrase What is &cp and what function is |?我很好奇短语 What is &cp 和 what function is | 的功能? I'm also curious about the function of if...endif我也很好奇 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 .请参阅: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 .请参阅: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: &cp&compatible是一个表达式,如果设置了compatible选项,则计算结果为1 (在 vimscript 中为真),如果禁用它,则计算结果为0 (假):

if &cp | <do something> | endif

See :help 'compatible' and :help expr-option请参阅:help 'compatible':help expr-option

The statement between the :if and the :else is set nocp , which unsets compatible : :if:else之间的语句set nocp ,它取消设置compatible

if &cp | set nocp | endif

So, that line tells Vim to check if compatible is set and, if yes, to unset it.因此,该行告诉 Vim 检查是否设置了compatible ,如果是,则取消设置。


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. FWIW, compatible当 Vim 在预期位置遇到vimrc时会自动取消设置,因此&cp在你的~/.vimrc中总是会被评估为0 ,这基本上使该行在你不应该使用的非常特定的用例之外无用如果你不得不问这个问题,你会遇到。

&cp -- value of Vim option cp ( :h 41.3 , :h 'cp' ), | &cp -- Vim 选项cp的值 ( :h 41.3 , :h 'cp' ), | -- another command in same command line ( :h :bar ), if ... endif -- conditional expression ( :h :if ). -- 同一命令行中的另一个命令 ( :h :bar ), if ... endif -- 条件表达式 ( :h :if )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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