Map multiple piped commands in vim

Posted on June 22, 2007 in Vim

If you want to map multiple commands in vim do it like this:

nmap :w|!ruby %>;CR>

imap :w|!ruby %

This writes the actual file to disk and evaluates it through the ruby interpreter when you hit the F1-key.

Alternatively you can do a:

:nmap <F1> :w|rubyf %<CR> (no space after the %)

:imap <F1> <Esc>:w|rubyf %<CR>

which should be faster, condition is you have to build vim with ruby support, but sometimes i get no results with this , vim gets crashed or does not respond anymore to me...

This mappings work both in insert- and command-mode