在 vimrc 中,如何在一个 Leader 命令中链接多个指令

在 vimrc 中,如何在一个 Leader 命令中链接多个指令

在我的 .vimrc 中我有:

map <Leader>c :GitGutterToggle<CR>
map <Leader>n :set invnumber<CR>

有什么方法可以将这两个合并为一个 Leader 条目吗?

例如:

map <Leader>c :GitGutterToggle && :set invnumber<CR>

我已经尝试了上述方法及其变体,但无济于事。

谢谢。

答案1

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:

接下来是命令列表,才不是include: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'.

因此,假设您没有修改cpoptions

map <Leader>c :GitGutterToggle <bar> :set invnumber<CR>

注意你应该使用noremap(以及更具体的nnoremapvnoremap等)映射命令,这样您就不会对您的映射感到惊讶。

相关内容