在我的 .vimrc 中我有:
map <Leader>c :GitGutterToggle<CR>
map <Leader>n :set invnumber<CR>
Run Code Online (Sandbox Code Playgroud)
有什么方法可以将这两者合并为一个 Leader 条目吗?
例如:
map <Leader>c :GitGutterToggle && :set invnumber<CR>
Run Code Online (Sandbox Code Playgroud)
我已经尝试过上述方法及其变体,但无济于事。
谢谢。
Vim 用于|链接 ex 命令。从:h cmdline-lines:
: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:
Run Code Online (Sandbox Code Playgroud)
接下来是命令列表,其中不包括:map或其变体。因此,您需要使用\|. 帮助的下面有一条关于 的注释:map,它导致:h 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'.
Run Code Online (Sandbox Code Playgroud)
所以,假设您没有修改cpoptions:
map <Leader>c :GitGutterToggle <bar> :set invnumber<CR>
Run Code Online (Sandbox Code Playgroud)
请注意,您应该使用noremap(以及更具体的nnoremap、vnoremap等)映射命令,这样您就不会因映射而感到惊讶。