sorry for the bad title. I could not think of how to better summarise the problem. I should also state, that I am fairly new to vim, so please be a bit considerate :).

I made the following changes in my vimrc file:

set whichwrap+=<,>,[,]
nmap k gk
nmap j gj

nmap <up> k
nmap <down> j

imap <up> <Esc>kli
imap <down> <Esc>jli

In normal mode, it works as desired. In insert more, it does work mostly all right, but the problem comes, when I hit an empty line. I am thrown out of the insert mode. I do not understand why, as it does end with an "i". I tried running these commands "by hand", i.e., typing them out as <Esc>, followed by j, l and i. It works as I would want it to. But when I press <down>, it still kicks me out of the insert mode...

I am using vim 8.2.3458, on linux, in alacritty. Usually, I also use vimtex, but I have disabled it (and everything else) for the purposes of testing and it still made no difference.

Anyone got any ideas? Cheers.

Edit: If I may ask, does this error reproduce for others as well? I know, it is a bit rude to ask this, but at least it would allow me to know, if it is the above code, or something else, that is messed up in my vim install..

  • Could you have a try with the nnoremap version of nmap and the inoremap version of imap? The third block of mapping you introduce is interacting with the first at the moment and it is probably not what you want. Apr 9, 2022 at 12:17
  • Thank you. I tried it, unfortunately, it does not work :(. Same error.
    – I.P
    Apr 9, 2022 at 12:36
  • In my tests the problem occurs only when you go down in a line with no characters or with less character that your current position. I believe the command stops at the first failure. Because the l parts can be executed without failure the i part is not executed and you stay in normal mode. Apr 9, 2022 at 13:01

1 Answer 1


When a mapping is executed it is translated to a list of commands. If one of them fail the execution is interrupted (like in a macro).

In your mapping: imap <down> <Esc>jli if the l command fails the i command is not executed.

If after going one line down, as the result of the j command, you are at the end of the line, the l command will fail and the i command will not be executed.

Remark: if you add l to whichwrap, which is not recommended, the l command will not fail if the cursor is at the end of the line and you will go back to insert more often.

set whichwrap+=l

  • Awesome, thanks. That does it, and the explanation makes sense, too. At some point, if the "set whichwrap+=l" it not sufficient, I might experiment further, maybe try to do an "if statement", (if vim allows that, as I said, I am rather new). But for now it works as desired. Thanks! (Sadly, not enough rep to upvote, but it is the right solution).
    – I.P
    Apr 9, 2022 at 13:18
  • You are welcome, thanks for nice words :-) Apr 9, 2022 at 13:39

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.