[英]What is the meaning of a <CR> at the end of some vim mappings?
我看<cr>
sa在VIM映射很多,但它有什么作用?
:help key-notation
says: 说:
notation meaning equivalent decimal value(s)
-----------------------------------------------------------------------
<CR> carriage return CTRL-M 13 *carriage-return*
<Return> same as <CR> *<Return>*
<Enter> same as <CR> *<Enter>*
Mappings often involve Ex commands and you must press <CR>
to execute them so it's included in the mapping. 映射通常涉及Ex命令,您必须按
<CR>
才能执行它们,因此它包含在映射中。
<special keys>
? <special keys>
? While you can use literal keys in mapping definitions (the Enter key would appear as ^M
, or even just as an additional new line, depending on the settings), Vim provides a special key notation for key (combinations), so that it is easier to define (you don't have to use i_CTRL-V
to literally insert the special character) and understand ( <Aa>
better expresses the intention than the equivalent á
) the mappings. 虽然你可以在映射定义中使用文字键(Enter键显示为
^M
,或者甚至只是作为一个额外的新行,具体取决于设置),Vim为键(组合)提供了一个特殊的键符号,因此它是更容易定义(您不必使用i_CTRL-V
来逐字插入特殊字符)并理解( <Aa>
更好地表达意图而不是等效的á
)映射。
See :help key-notation
for a list and explanation. 请参阅
:help key-notation
以获取列表和说明。
<CR>
? <CR>
? As many mappings invoke Ex commands (eg :w
) and therefore have to switch from normal to command-line mode, they have to conclude the command with <Enter>
(or <CR>
), just as you would when manually typing the command. 由于许多映射调用Ex命令(例如
:w
),因此必须从正常模式切换到命令行模式,因此必须使用<Enter>
(或<CR>
)结束命令,就像手动键入命令时一样。
vim
映射中的<CR>
是回车 键 ,通常是键盘上的Enter键。
<CR>
in a mapping corresponds to the Enter key just like a
in a mapping corresponds to the A key. <CR>
在映射对应于就像回车键a
在映射对应于一个关键。 Ley's say you have this mapping 莱伊说你有这个映射
:map <f8> :wq<cr>
This will map F8 to the key sequence : W Q Enter (which would save the current buffer and quit). 这会将F8映射到键序列: W Q Enter (将保存当前缓冲区并退出)。
It's basically a means to say "this is the end", see map : 它基本上是一种说“这就是结束”的方法,见地图 :
When you have a mapping that contains an Ex command, you need to put a line terminator after it to have it executed.
如果您有一个包含Ex命令的映射,则需要在其后面添加一个行终止符以使其执行。 The use of is recommended for this.
建议使用此方法。 Example:
例:
:map _ls :!ls -l %<CR>:echo "the end"<CR>
also, 也,
<CR> [count] lines downward, on the first non-blank character |linewise|.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.