define a KeyMap which combines two command

0 views
Skip to first unread message

Steven Woody

unread,
Dec 9, 2008, 12:22:11 AM12/9/08
to Vim
Hi,

I know use '|' and combine two command, but I don't know how to do
the combination when the first command is a external shell command
(prefixed by a '!').

For example, I want to define <F5> to run a shell command which
updates my cscope database and then run ':cs reset', I tried

nmap <F5> :!./recs-sh | :cs reset<CR>

but it failed.

Anyone can be kindly help?

-
narke

Gary Johnson

unread,
Dec 9, 2008, 2:12:44 AM12/9/08
to vim...@googlegroups.com

The :execute command can help here.

nmap <F5> :exe '!./recs-sh' | cs reset<CR>

Note that the colon is needed only at the start of the command line,
not in front of each command.

See

:help :exe

Regards,
Gary

Teemu Likonen

unread,
Dec 9, 2008, 2:24:13 AM12/9/08
to vim...@googlegroups.com
Gary Johnson (2008-12-08 23:12 -0800) wrote:

> On 2008-12-09, Steven Woody wrote:
>> nmap <F5> :!./recs-sh | :cs reset<CR>
>>
>> but it failed.

> The :execute command can help here.


>
> nmap <F5> :exe '!./recs-sh' | cs reset<CR>
>
> Note that the colon is needed only at the start of the command line,
> not in front of each command.

it's also possible to put <CR> between the commands. Then the colon is
needed with the second command:

nmap <F5> :!./recs-sh<CR>:cs reset<CR>

Steven Woody

unread,
Dec 9, 2008, 2:40:00 AM12/9/08
to vim...@googlegroups.com

Thank you! It is a rescue.

Tony Mechelynck

unread,
Dec 9, 2008, 12:15:42 PM12/9/08
to vim...@googlegroups.com

Normally, the | character terminates the ":map" command. To use it in a
{rhs}, use <Bar> instead.


Best regards,
Tony.
--
In case of injury notify your superior immediately. He'll kiss it and
make it better.

Reply all
Reply to author
Forward
0 new messages