5

In my .vimrc I have:

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

Is there any way I can combine these two into one Leader entry?

For example:

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

I've tried the above, and variations thereof, to no avail.

Thanks.

Kevin
  • 151

1 Answers1

7

Vim uses | to chain ex commands. From :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:

This is followed by a list of commands, which does not include :map or its variants. So, you'll need to use \|. Further down the help is a note about :map, which leads to :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'.

So, assuming you haven't modified cpoptions:

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

Note that you should use noremap (and the more specific nnoremap, vnoremap, etc.) map commands so that you don't surprised by your mappings.

muru
  • 207,228