4

Whenever I use vim, and press up, down, left, or right, it maps to A, B, C, D respectively but only in insert mode. Outside of insert mode, the keys work just fine. I checked the .vimrc file and didn't see anything suspicious that could cause this.

I'm on a Mac, OS X 10.8 and on VIM 7.3.923 (just upgraded, that didn't resole any problems either).

I ran :map which resulted in:

gx            <Plug>NetrwBrowseX                                                                                                                                                               
<Plug>NetrwBrowseX * :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<CR>
<BS>          "-d
<D-x>         "*d
<D-c>         "*y
<D-v>         "-d"*P
<D-v>         "*P

And :imap which resulted in:

<D-v>         <C-R>*

Ideas?

antjanus
  • 987
  • 3
  • 15
  • 30
  • 1
    [Fix arrow keys that display A B C D on remote shell](http://vim.wikia.com/wiki/Fix_arrow_keys_that_display_A_B_C_D_on_remote_shell) – devnull May 31 '13 at 13:21

3 Answers3

10

Have you mapped the escape key?

I had the same issue when I tried remapping the escape key to clear out search highlighting.

Kronenbourg
  • 311
  • 3
  • 6
  • I had the exact same problem. Don't understand why mapping the escape key (I used `nnorem :nohlsearch`) would affect the arrow keys, though. – sevko Dec 05 '16 at 04:45
  • I tried the exact same thing and ran into the exact same problem - took a lot of googling before I finally tracked the problem to this answer. WTF? – Paul Siegel May 31 '17 at 02:56
  • Yeah I'm seeing this as an issue only when I map the escape key. Anybody have any ideas on this? – jerome Jun 15 '17 at 17:21
4

You could try to turn off compatible mode.
This is generally a good idea (better safe than sorry) even if you don't have this problem.

set nocompatible

It might also be a problem with your $TERM, among other things.
See Fix arrow keys that display A B C D on remote shell for more information.

Community
  • 1
  • 1
timss
  • 9,982
  • 4
  • 34
  • 56
  • 1
    The mere presence of a `.vimrc` file disables compatible mode as long as it's not explicitly set in the `.vimrc`. Not a knock on this answer, just a useful piece of related info. – Randy Morris May 31 '13 at 13:22
  • I used the answer in the link, everything works fine now. Thanks! – antjanus May 31 '13 at 13:24
  • @RandyMorris Thanks, updated my answer. Better safe than sorry as the answer in the linked post said I guess. – timss May 31 '13 at 13:32
  • I used the first solution in the Fix arrow keys that display A B C D on remote shell link (remapping the arrow keys). Everything worked correctly afterward. – antjanus May 31 '13 at 14:12
  • Using *Cygwin*, in addition to the first solution, I had to add `alias vi="vi -u ~/.vimrc"` to my *~/.bash_aliases* files. For some reason it seems like `vi` wasn't picking up my *~/.vimrc* file. – Batandwa May 12 '14 at 08:46
  • @Batandwa That may be something with the Cygwin version of Vi. I've used Vim with Cygwin and did not have to do such a thing. – timss May 12 '14 at 10:06
  • I had to set `TERM` to `xterm` in konsole (Settings > Edit Current Profile... > Environment > Edit... > enter: `TERM=xterm`) – Alfred Bez Feb 20 '16 at 12:41
1

In OS-X, in Terminal, go to Preferences > Profiles > Advanced > Declare Terminal as vt102.

Twitch
  • 664
  • 1
  • 7
  • 26