В vimrc, как я могу объединить многоадресные команды в цепочку в одной команде Leader

В моем .vimrc я имею:

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

Есть ли какой-либо способ, которым я могу объединить эти два в одну запись Лидера?

Например:

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

Я попробовал вышеупомянутое и изменения этого, напрасно.

Спасибо.

1
задан 16 April 2017 в 18:40

1 ответ

Использование Vim | к цепочке исключая командами. От :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:

Это сопровождается списком команд, который не включает :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 (и более определенное nnoremap, vnoremap, и т.д.), отображают команды так, чтобы Вы не делали удивленный Вашими отображениями.

3
ответ дан 7 December 2019 в 12:33

Другие вопросы по тегам:

Похожие вопросы: