History Report a problem
Article Edit this page Discussion

Fix arrow keys that display A B C D on remote shell

From Vim Tips Wiki

(Redirected from VimTip550)
Jump to: navigation, search
 

Tip 550Previous TipNext Tip

Created: September 5, 2003 Complexity: basic Author: VT Minimum version: 6.0 Karma: 135/49 Imported from: Tip#550


I wonder how many of you are annoyed with the arrow key behavior during insert mode in Vim.

Leave all the key mappings default, do not change your TERM environment. Here's a simple tip,

:set term=cons25

It was tested with Vim 5.8 and 6.1 editions on; FreeBSD 4.X-STABLE; xterm(-color),VT100 remote terminals; (t)csh shells.

[edit] Comments

 

This doesn't really work very well for me on SunOS -- I have the same problem but :set term=cons25 just gives me OC everywhere before each character until I redraw. Weird.

But, :set term=ansi works great, and the arrow keys work.

A better solution is to, while in vi, type in insert mode [ctrl-v][arrow up] and see what you get. Then, in your .vimrc, add the lines

set t_ku=[ctrl-v][esc]OA # or whatever you saw

so it ends up looking something like

set t_ku=^[OA
set t_kd=^[OB
set t_kr=^[OC
set t_kl=^[OD

(though you want REAL escape chars instead of ^[.)


And in addition, set term=ansi makes syntax color off in vim (afair FreeBSD with color xterm).


So are we to be left with no good freebsd / bash solution?

set t_ku=^[OA
set t_kd=^[OB
set t_kr=^[OC
set t_kl=^[OD

did nothing for me... and the no environment option is not a good one. I have looked everywhere for the answer and found nothing...

btw set mouse=a at least allows me to move in insert mode.


I had the same problem a few days ago. I figured out that i didnt have the ~.vimrc file. So, i went to /usr/local/share/vim/vim58 and copied the vimrc_example.vim to ~.vimrc. Problem solved!


I can confirm that the arrow-key problem (under freebsd) disappeared as soon as I introduced .vimrc


The :set nocompatible method I *think* solves the arrow keys. It is in the default vimrc_example.vim. So copying that to ~/.vimrc should solve your problem as others have noted.


Works even for Linux - VI's arrow key problem in insert mode disappears when we copy the example vim file (in vim version7 the file is - vimrc_example.vim) as .vimrc in the home directory.

I wish this solution got mentioned at the top of this page, saves time.


The reason why copying the default .vimrc file works is because it issues a set nocompatible ... just read the default vimrc file and things start to work much better :)


Do this:

$ vim ~/.vimrc
set t_ku= (now type Ctrl-V and press cursor up)
set t_kd= (now type Ctrl-V and press cursor down)
set t_kr= (now type Ctrl-V and press cursor right)
set t_kr= (now type Ctrl-V and press cursor left)

You should get something that looks like

set t_ku=^[OA
set t_kd=^[OB
set t_kr=^[OC
set t_kl=^[OD

but the ^[ is actually a single escape character.

That certainly works for me here (FreeBSD 6.1, ssh in from Mac OS)


It also appears that it must be started as "vim" rather than "vi" in order to read the .vimrc file. I've added an alias to my bashrc scripts to take care of this... "alias vi=vim"


If you are using vi instead of vim, you need to update the above commands in .exrc file instead of .vimrc. Since alias makes you to work in vim, even you type vi.

Rate this article:

Share this article:

Hubs Highlights International Sites Wikia messages
Entertainment
Gaming
Cartoons & Comics
Science Fiction
Hobbies
Sports
See all...
Grand Theft Auto
Doctor Who
Legend of Zelda Wiki
Terminator Wiki
Everquest II Wiki
Mystery Science Theater 3000
German
Spanish
Chinese
Japanese
More...
Wikia is hiring for several open positions
Send this article to a friend
"Fix arrow keys that display A B C D on remote shell"
 
 
Hi!

I thought you'd like this page from Wikia!

http://vim.wikia.com

Come check it out!
Send confirmation