Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to map a long bash command in vim?

Tags:

shell

vim

call

The shell command can kill chrome process.

ps -ef | grep chrome |awk '{print $2}'| xargs kill

Now I want to map the character - with above bash command.

nnoremap  -  :!ps -ef | grep chrome |awk '{print $2}'| xargs kill

It takes no effect, how to map my bash command?

like image 672
showkey Avatar asked Mar 15 '16 05:03

showkey


1 Answers

Escape the pipes

Every pipe has to be escaped. Then append it with <CR> so you don't have to press enter all the time.

nnoremap - :!ps -ef \| grep chrome \|awk '{print $2}'\| xargs kill<CR>

Kill'Em All

Note also, that we have a cute little tool to kill'em all. So instead of

ps -ef | grep chrome |awk '{print $2}'| xargs kill

you can do

killall chrome

Your mapping then will be

nnoremap - :!killall chrome<CR>
like image 100
pacholik Avatar answered Nov 04 '22 23:11

pacholik