it_is_a_literature it_is_a_literature - 2 years ago 79
Bash Question

How to map a long bash command in vim?

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?

Answer Source

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>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download