I would like to disable arrow keys in all modes. This is what I tried:
"EDIT: added remap for <esc> as per the comments inoremap <esc> <nop> inoremap <up> <nop> inoremap <down> <nop> inoremap <left> <nop> inoremap <right> <nop> "inoremap <ESC>oA <nop> "inoremap <ESC>oB <nop> "inoremap <ESC>oC <nop> "inoremap <ESC>oD <nop> nnoremap <up> <nop> nnoremap <down> <nop> nnoremap <left> <nop> nnoremap <right> <nop> vnoremap <up> <nop> vnoremap <down> <nop> vnoremap <left> <nop> vnoremap <right> <nop>
This works fine for normal and visual modes, but in insert mode it starts writing funny characters if I press the arrow keys, like
What is the reason that the arrow keys behave differently in insert mode than normal/visual modes? (Or do they actually behave the same, and
OCOAOB has no effect in normal/visual modes?)
Update: It turned out that the cause for the behaviour was the remapping of the
esc key (thanks to @filbranden for pointing that out!)
However, the question is still open: why do the remapped arrow keys in insert mode behave differently, if the
esc key is also remapped?
- I am running Ubuntu and using Vim in a local terminal (i.e. not ssh'ing somewhere remotely)
- I already found this answer, and tried to change all kinds of terminal settings/nocompatible mode. The only difference I could achieve was this:
[C[C[C[C[D[D[D[D[D[C[C[A[B[D[C. (EDIT: this is caused e.g. by
- The issue is reproducible also with a minimal
.vimrccontaining only the lines above (i.e., it is not due to a plugin interferring).
- By uncommenting the commented lines, the problem is fixed, but 1. I would really like to understand what is going on; 2. that solution feels a bit hacky to me, although it works.
Answer to comments
:set term? t_ku? term=screen-256color t_ku <Up> ^[OA
Platform, OS: Ubuntu 19.04 on x86_64, terminal vim
Pressing arrows in terminal:
$ cat ^[[A^[[B^[[A^[[C^[[D^[[C^[[B^[[A
vim -u NONE -N
--> problem is not reproducible
/etc/vim/vimrc (comments removed):
runtime! debian.vim if has("syntax") syntax on endif if filereadable("/etc/vim/vimrc.local") source /etc/vim/vimrc.local endif