4

I'm trying to have something like this in my .vimrc:

nnoremap <leader>has :w | ! reset; runhaskell % <cr>

How ever, now it prompts an error when loading .vimrc and tells me:

:! reset; runhaskell r_packages.markdown 
/bin/bash: -c: line 0: syntax error near unexpected token `newline'
/bin/bash: -c: line 0: ` reset; runhaskell r_packages.markdown '

How should I write my key mapping so as the bash command is executed only on my leader key mapping ? And not when vim starts up.

1 Answer 1

7

Vim interprets the pipe character as a command termination and tries to execute what's afterwards as if it was an Ex command which was not part of the nnoremap mapping.
To prevent this, you have to escape the pipe or replace it with the corresponding keycode <bar>:

nnoremap <leader>has :w <bar> ! reset; runhaskell % <cr>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.