以下是一些实验,用于演示|
,<Bar>
和\|
在Vim命令的不同场景中的表现。
下面的代码块显示了每个命令(或命令集)的几个Vim命令,然后是对命令行为方式的快速评论。
:!uname | new
/bin/bash: new: command not found
:!uname <Bar> new
/bin/bash: Bar: no such file or directory
:!uname \| new
usage: uname [-amnprsv]
:!uname | grep i
Darwin
结论:
|
作为文字|
传递给shell。<Bar>
作为文字<Bar>
传递给I / O重定向。\|
作为文字|
传递给shell。所以在这种情况下,所有三个命令的行为都相似,从某种意义上说,你看到的是传递给shell的内容。所以这很容易理解。
:command! A !uname | new
:A
/bin/bash: new: command not found
:command! A !uname <Bar> new
:A
/bin/bash: new: command not found
:command! A !uname \| new
:A
usage: uname [-amnprsv]
:command! A !uname | grep i
:A
Darwin
:command! A !uname <Bar> grep i
:A
Darwin
结论:
|
和<Bar>
行为相似(作为|
传递给shell)。\|
行为不同(作为文字\|
传递给shell)。:map ,a :!uname | new<CR>
,a
Creates a new window when the `:map` command is executed.
Enters `!uname` in the command-line-mode when `,a` is pressed.
:map ,a :!uname <Bar> new
,a
Enters `:!uname | new` in the command mode.
:map ,a :!uname \| new
,a
Enters `:!uname | new` in the command mode.
结论:
|
行为不同(:map
与另一个Vim命令之间的命令分隔符,在这种情况下为new
。<Bar>
和\|
行为相似(执行map-rhs时它们变为|
。:new | vnew
Creates split windows
:new <Bar> vnew
Creates a single split window with file named `<Bar> vnew`
:new \| vnew
Creates a single split window with file named `| vnew`
结论:
|
表现不同(作为命令分隔符)。\|
和<Bar>
行为相似(作为文字参数)。:command! A new | vnew
:A
Creates split windows.
:command! A new <Bar> vnew
:A
Creates split windows
:command! A new \| vnew
:A
Creates a single split window with file named `| vnew`
结论
|
和<Bar>
的行为相似(在命令运行时期间作为命令分隔符)。\|
表现不同(在命令运行时期间作为new
的文字参数)。这与上面的案例2一致。
:map ,a :new | vnew
,a
Creates a new window when the `:map` command is executed.
Enters `new` in the command-line-mode when `,a` is pressed.
:map ,a :new <Bar> vnew
,a
Enters `:new | vnew` in the command-line-mode when `,a` is pressed.
:map ,a :new \| vnew
,a
Enters `:new | vnew` in the command-line-mode when `,a` is pressed.
结论:
|
行为不同(:map
与另一个Vim命令之间的命令分隔符,在这种情况下为new
。<Bar>
和\|
行为相似(执行map-rhs时它们变为|
)这与上面的案例3一致。这是有道理的,因为这种情况与案例2基本相同,即:map
将键击重新映射到命令行模式命令。
:bn | bn
Goes to the 2nd next buffer.
:bn <Bar> bn
E488: Trailing characters
:bn \| bn
Goes to the 1st next buffer. What happened to `\| bn`?!
结论:
|
,<Bar>
和\|
的所有三个行为都不相同。:command! A bn | bn
:A
Goes to the 2nd next buffer.
:command! A bn <Bar> bn
:A
Goes to the 2nd next buffer.
:command! A bn \| bn
:A
Goes to the 1st next buffer.
结论:
- |
和<Bar>
行为相似(在命令运行时期间作为命令分隔符)。
- \|
的行为就像\|
在\|
中被bn \| bn
字面用作:map ,a :bn | bn
,a
Switches to the next buffer when `:map` command is executed.
Enters `:bn` in the command-line-mode.
:map ,a :bn <Bar> bn
,a
Enters `:bn | bn` in the command-line-mode.
:map ,a :bn \| bn
,a
Enters `:bn | bn` in the command-line-mode
一样,产生了令人困惑的行为,如前一种情况所示。
此行为与案例2和案例5一致。
|
这与上面的案例3和案例6一致。
关于如何在各种命令中解释<Bar>
,\|
和cpoptions
假设Vim的默认设置(默认情况下),有哪些权威规则(根据权威Vim文档或参考) :map
,普通:command
和os.makedirs(r'\\SERVERNAME\SharedFolder\NewFolder')
命令等)?
答案 0 :(得分:0)
发布此问题后,我一直在研究Vim的:help
以收集尽可能多的线索。这是一个几乎似乎有用的理论。我收录了Vim :help
的相关文档,我可以找到它来支持每一点。
:!
,|
,<Bar>
和\|
按字面传递给shell命令。
*:!cmd* *:!* *E34*
:!{cmd} Execute {cmd} with the shell. See also the 'shell'
and 'shelltype' option.
...
A '|' in {cmd} is passed to the shell, you cannot use
it to append a Vim command. See |:bar|.
许多命令行模式命令(例如map
但不是:command
或:!
)在遇到|
时结束,因为这是命令分隔符。< / p>
*:bar* *:\bar*
'|' can be used to separate commands, so you can give multiple commands in one
line. If you want to use '|' in an argument, precede it with '\'.
These commands see the '|' as their argument, and can therefore not be
followed by another Vim command:
:argdo
:autocmd
:bufdo
:cdo
:cfdo
:command
...
:make
:normal
...
:[range]!
请务必在上面的列表中注意,虽然:command
和:!
使用|
作为参数,但:map
却没有。这在下面的第4点非常重要。
除非文档中针对某些命令行模式命令的<Bar>
和\|
记录了某些特殊行为,否则这些行为将按字面意思使用。这可以解释上面第1点中<Bar>
和\|
的行为。但它无法解释<Bar>
在下面第4点的行为。
使用:command
时,|
和<Bar>
在执行用户定义的命令时,在运行时替换命令文本中的行为类似于命令分隔符。
*:bar* *:\bar*
...
These commands see the '|' as their argument, and can therefore not be
followed by another Vim command:
:argdo
:autocmd
:bufdo
:cdo
:cfdo
:command
...
:make
:normal
...
:[range]!
不清楚为什么<Bar>
在本文档中|
的行为与:command
的行为相似。
使用:command
时,在执行用户定义的命令时,\|
在运行时在替换命令文本中作为文字\|
参数传递。
*:bar* *:\bar*
'|' can be used to separate commands, so you can give multiple commands in one
line. If you want to use '|' in an argument, precede it with '\'.
使用:map
,|
是map
命令和第二个Vim命令之间的命令分隔符。执行map
命令并定义用户定义的命令后,将立即执行第二个Vim命令。执行用户定义的命令时不执行它。这直接来自上面第2点引用的Vim文档。
使用:map
,<Bar>
和\|
在用户定义的命令的运行时就像一个命令分隔符。
*map_bar* *map-bar*
Since the '|' character is used to separate a map command from the next
command, you will have to do something special to include a '|' in {rhs}.
There are three methods:
use works when example ~
<Bar> '<' is not in 'cpoptions' :map _l :!ls <Bar> more^M
\| 'b' is not in 'cpoptions' :map _l :!ls \| more^M
^V| always, in Vim and Vi :map _l :!ls ^V| more^M
(here ^V stands for CTRL-V; to get one CTRL-V you have to type it twice; you
cannot use the <> notation "<C-V>" here).
All three work when you use the default setting for 'cpoptions'.
此外,
*key-notation* *key-codes* *keycodes*
These names for keys are used in the documentation. ...
...
<Bslash> backslash \ 92 *backslash* *<Bslash>*
<Bar> vertical bar | 124 *<Bar>*
<Del> delete 127
...
For mapping, abbreviation and menu commands you can then copy-paste the
examples and use them directly. Or type them literally, including the '<' and
'>' characters. This does NOT work for other commands, like ":set" and
":autocmd"!
此外,
SPECIAL CHARACTERS
The ":map" command can be followed by another command. A | character
separates the two commands. This also means that a | character can't be used
inside a map command. To include one, use <Bar> (five characters). Example:
:map <F8> :write <Bar> !checkin %:S<CR>
仍然无法解释的行为:
<Bar>
的行为与|
中的:command
相似? (请注意,<Bar>
在<Bar>
命令中以:!
字面意思传递给shell。我不明白为什么它应该像|
中的:command
一样。 )