I want to disable the arrow keys in Insert mode, since I want to force myself to always go into Normal mode for performing movements.

To achive this, I've made the following mappings for Insert mode, which should (AFAIK) make the arrow keys have no effect (NOP).

However, pressing e.g. <left> in Insert mode results in 0D being written in the buffer, which is not want I want.

How can I disable the arrow keys without "side-effects"?

" Disable arrow keys (Insert mode)
inoremap <left> <nop>
inoremap <down> <nop>
inoremap <up> <nop>
inoremap <right> <nop>

enter image description here

  • 1
    If you use a .vimrc with only those 4 statements and invoke vim --noplugin, does the problem still happen? – Quasímodo Sep 12 '20 at 10:35
  • Thank you. Using vim -u /dev/null --noplugin makes the arrow keys result in A, B, C, and D. – Shuzheng Sep 12 '20 at 11:07
  • 1
    Arrow keys send special codes in a terminal that start with escape (in my terminal, that would be Escape followed by OA, OB, OC, and OD). Remapping escape tends to break things; it’s possible this is related. – D. Ben Knoble Sep 12 '20 at 13:01
  • @D.BenKnoble - I'm not sure what you mean. ` vim -u /dev/null --noplugin` makes it certain that I load no ~/.vimrc file and that no plugins in ./vimrc/pack is loaded right (please confirm)? Then why do arrow keys result in those codes? I manually execute :inoremap <left> <nop> in Ex mode, and verify the result using :inoremap. – Shuzheng Sep 12 '20 at 16:20
  • 1
    Do not remap escape. It breaks things because it breaks how vim handles special codes (such as those used the terminal for drawing, handling arrow keys, etc.) – D. Ben Knoble Sep 12 '20 at 18:26