I use this keymapping toggle to highlighting on and off, but when I originally found it, the author did not list two <cr> at the end of the command. I found that if I didn't have two <cr> there, then I was required to press Return after my keymapping. Why? ... because now that I can get the macro (wrong term?) to execute, my cursor advances to the next line after executing the mapping.

highlight OverLength ctermbg=gray
match OverLength /\%81v.\+/
let OLstate = 1
nnoremap oi : if (OLstate == 0) \| match OverLength /%81v.\+/ \| else \| match OverLength /%9999v/ \| endif \| let OLstate = 1 - OLstate <cr> <cr>

1 Answer 1


I think you want

: ... endif <cr> :let OLstate = 1 - OLstate <cr>

instead of

: ... endif \| let OLstate = 1 - OLstate <cr> 

That is, <cr> after the endif, a : before let and <cr> after the let statement. There are two commands.

I'm using vim 7.4, plain vanilla, no .vimrc, no plugins.

  • By golly, that was it! ... so to make sure I understand this right: It was failing because the first :if command should be entered and executed (terminating in that <cr>), and then the :let command should be entered and executed - but my original code had one long command (actually two nested commands?) not properly executing in order... resulting in the need for two <cr>s to execute first the inner-nested command and then the outer-nested command? Commented Jun 8, 2018 at 17:50

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.