darryn.ten
darryn.ten

Reputation: 6973

Arrow keys in vim (linux) in insert mode broken for me

When I use the arrow keys in vim in insert mode I get letters inserted instead of movement.

Does anyone know what would cause this?

Thanks in advance

Upvotes: 3

Views: 4667

Answers (5)

Alessandro Pezzato
Alessandro Pezzato

Reputation: 8802

None of the answer here worked for me. I'm in Linux, with konsole/yakuake terminal and tmux. This fix works for me:

nnoremap <silent> <ESC>OA <ESC>ki
nnoremap <silent> <ESC>OB <ESC>ji
nnoremap <silent> <ESC>OC <ESC>hi
nnoremap <silent> <ESC>OD <ESC>li
inoremap <silent> <ESC>OA <ESC>ki
inoremap <silent> <ESC>OB <ESC>ji
inoremap <silent> <ESC>OC <ESC>hi
inoremap <silent> <ESC>OD <ESC>li

Upvotes: 1

vitaluha
vitaluha

Reputation: 183

The following worked for me. Just put it in your .vimrc

:set term=cons25

Upvotes: 4

hcg
hcg

Reputation: 652

  1. Open Vim editor.
  2. Get the path of your home directory by typing: :echo $HOME.
  3. Check if you have .vimrc file in $HOME location, and if you don't have create it.
  4. Add the following line line to .vimrc file: :set nocompatible

Reference: http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell

Upvotes: 2

ZyX
ZyX

Reputation: 53604

If these keys work fine in normal mode, but do not in insert then you must have some mappings to the first one or two characters (normally <Up> is either <Esc>[A (terminals that use CSI) or <Esc>OA (xterm)). Try checking out output of

verbose imap <Esc>

, there should be not much mappings starting with <Esc> in insert mode (I have none, for example). I can say, that with arrow keys working normally in insert mode, using

inoremap <Esc> <Esc>

produces just the same behavior as if you had problems with terminal recognition or had 'compatible' set.

Upvotes: 7

Pavan Manjunath
Pavan Manjunath

Reputation: 28525

Your vim seems to be starting in the vi compatibility mode. Do this

  • Open Vim editor,
  • Get the path of your home directory by typing :echo $HOME
  • Check if you have .vimrc file in $HOME location,(if you don't have create it)
  • Add the following line line to .vimrc file :set nocompatible

Find more solutions for the same problem here ( Especially if your problem is terminal related, the re-mapping of keys solution might work for you )

Upvotes: 7

Related Questions