How to map two commands on one key?

0 views
Skip to first unread message

frank wang

unread,
Jan 6, 2010, 8:54:04 PM1/6/10
to v...@vim.org
Hi,

I am trying to map two commands on one key such as:

nmap <C-\>g :call add(SrcExpl_markList, [expand("%:p"), line("."),
col(".")]) :cs find s <cword>

The command will push the current position to the SrcExpl_markList and
execute the cscope command cs find s <cword>. However, every time when
I type the key <C-\>g,
the command will be shown on the command line as
:call add(SrcExpl_markList, [expand("%:p"), line("."), col(".")]) :cs
find s <cword>

After I hit the enter, vim will complain E488: Trailing characters and
it will not jumt to the definition of <cword>. It seems the first part
of command call add(SrcExpl_markList, [expand("%:p"), line("."),
col(".")]) was executed correctly.

Does anyone know what I did wrong?

Thanks

Frank

Gary Johnson

unread,
Jan 6, 2010, 9:25:13 PM1/6/10
to vim...@googlegroups.com

The command separator is a bar (|). See

:help :bar

Your mapping would then be:

nmap <C-\>g :call add(SrcExpl_markList, [expand("%:p"), line("."), col(".")])\|cs find s <cword><CR>

You can also use "<Bar>" in place of "|" or "\|" in some contexts,
but I've never sure which and I didn't try it here.

I added <CR> so that you won't have to hit Enter after hitting the
mapped key.

Regards,
Gary


Tony Mechelynck

unread,
Mar 12, 2010, 6:18:03 PM3/12/10
to vim...@googlegroups.com

Mappings (and abbreviations) are the main context where <Bar> is useful:
in fact I avoid backslashes in mappings because (depending on
circumstances) they may have to be doubled for each level of
interpretation (when the mapping is defined, when it is interpreted,
etc.). All <> notation symbols shown at ":help keycodes" (which is just
_before_ ":help <>") can be used in mappings.


Best regards,
Tony.
--
There is a certain impertinence in allowing oneself to be burned for an
opinion.
-- Anatole France

Reply all
Reply to author
Forward
0 new messages