Saturday, June 12, 2004

VIM and arrow keys under FreeBSD

For some reason in insert-mode under FreeBSD, VIM doesn't process the arrow keys (up, down, right, left) such that the cursor moves in the expected direction. Instead I was getting [ABCD] every time I hit (up|down|left|right), respectively.

Under OpenBSD, this works fine with the "pcansi" terminal setting (under FreeBSD I am using the "screen" terminal setting, but have tried others to no avail). I suppose I am still a little unclear why this happens on FreeBSD and not on OpenBSD, and how it can be fixed such that they both work. In the mean time, I solved the problem with the help of the VIM Tips portal.

http://www.vim.org/tips/tip.php?tip_id=550

The solution I used is the one suggested by the first comment. Here it is:

1. Create a .vimrc using VIM.
2. Enter the following.

set t_ku=[CTRL-V][UP-ARROW]
set t_kd=[CTRL-V][DOWN-ARROW]
set t_kr=[CTRL-V][RIGHT-ARROW]
set t_kl=[CTRL-V][LEFT-ARROW]

Where [CTRL-V] is the actual control-V keypress, [UP-ARROW] is the up arrow and so on.

3. Save and quit VIM.

When you restart VIM and enter insert-mode ("i"), the arrow keys should move the cursor and not display ASCII characters.

1 comment:

Wayne said...

Worked for me in OpenBSD too! Thanks for the tip!