Wherein I occasionally rant on various topics including, but not limited to, PHP, Music, and whatever other Topics I find interesting at the moment, including my brain tumor surgery of August 2010.

Thursday, April 17, 2008

Solaris vi input mode arrow keys fix

This blog post is not for you to read.

It's for me.

You see, every once in a awhile, I work for a client/employer who uses Solaris, OpenSolaris, Unix, or some other traditional Unix-like OS.

They have their reasons, and they are good ones, and I'm fine with that.

Alas, I then usually waste about an hour of their time (and they pay me for it) to Google for the hack that makes vi (my editor of choice) actually usable from a terminal program (putty, usually).

To wit, the arrow keys in vi do not work in input mode under these OSes.

This blog post is a reminder for ME to know what the heck to do next time this happens.

So here is what I do:
Open up ~/.exrc and type these things:
set t_ku=[control-v][up-arrow]
set t_kd=[control-v][down-arrow]
set t_kr=[control-v][right-arrow]
set t_kl=[control-v][left-arrow]

Then make a symlink from .exrc to .vimrc
ln -s ~/.exrc ~/.vimrc

Finally, alias vi to vim, since this only works for vim:
alias vi=vim

Bonus Tip:
To get vi/vim to use more than ONE LINE when you start up, use:
TERM=putty screen

I believe "screen" is magical pixie dust that gives you a whole screen of line instead of one line, and the TERM stuff obviously tells screen that you need that screen to go to putty.

If "man screen" had been installed, perhaps I would have a better understanding of the magical pixie dust, but so it goes.

:-)

4 comments:

Nick said...

I read it anyway!

It was exactly what I'd been looking for, having just installed opensolaris for the first time.

Thanks!

Eric said...

Have you tried putting the following in you ~home/.exrc file (you can create one if it is not there)? I found this works for vi. (vim not needed)

map! ^[OA ^[ka
map! ^[OB ^[ja
map! ^[OD ^[i
map! ^[OC ^[la

Note: ^[ is the “ctrl-v Esc” key presses. Copy and paste will not work.

I also like turning off auto indenting for pasting into vi and not having it spread all over editor. Good for Oracle DBAs when pasting into tnsnames.ora files

To turn off auto indent add
:set noai

--Eric

Unknown said...

ooo, magical! works!
anyway, I copied and pasted at first, I didn't know I was supposed to actually type contol-v, and the up-arrow...

Now I don't have to use ansi terminal anymore :-)

Ludovic Kuty said...

Eric, it made my day. Thank you. I was looking for something like that for vi for years.