nnoremap <leader><cr> :execute "normal! i\\\<cr>\<esc>"

When I run that, it says:

E114: Missing quote: "normal! i\\\
E15: Invalid expression: "normal! i\\\

What's wrong with this? I'm trying to press i to go into insert mode, add a \ character, enter a newline, then escape.

1 Answer 1


You used the following command:

nnoremap <leader><cr> :execute "normal! i\\\<cr>\<esc>"

Here is the command which does what you want:

:nnoremap <leader><cr> :execute "normal! i\\\n"<cr>

First, <cr> has special meaning to :map (and :abbrev and a couple others). Most of the rhs of a mapping is processed literally, as if you were typing those characters. With <cr>, :map acts as if you hit Enter. That leaves you submitting :execute "normal! i\\\ ... an incomplete command and thus you get the "Missing quote" error. \n has no such special meaning, it's just another character and is passed to :execute in the string parameter.

Second, you don't need to explicitly escape just like you wouldn't if you directly entered :execute "normal! i\\\n". Once you hit Enter in that case (which we're doing in the mapping with the <cr> at the end) the insert occurs and you are returned back to command line.

If you really want to use <esc> ;) here's another way to do it...and I'm sure some folks would prefer this version...

:nnoremap <leader><cr> :star<cr>\<cr><esc>

(:star is short for :startinsert)


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.