Operating System - Linux
1752778 Members
6328 Online
108789 Solutions
New Discussion юеВ

Re: use of arrow buttons in vi editor

 
SOLVED
Go to solution
pb raju
Occasional Contributor

use of arrow buttons in vi editor

Hi ,

We are unable to use all arrow buttons in vi editor of our hp-ux server (rp3440 )
(right arrow L , down-arrow J etc).
We can use arrow buttons in vi editor only on Terminal and not on windows key board ( login by telnet).

Is there any mapping to be done to activate arrow keys on vi editor ?

Regards
Raju
10 REPLIES 10
Yogeeraj_1
Honored Contributor

Re: use of arrow buttons in vi editor

hi,

You must find a terminal emulation software that can emulate that.


In fact, some software allow you to do keyboard remapping such that when you press the arrow keys, it will emulate "right arrow L"

We had been using a terminal emulation software from FTP Software in the past.


hope this helps!



kind regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Steven E. Protter
Exalted Contributor

Re: use of arrow buttons in vi editor

Shalom Raju,

Thought the terminal software can be changed to meet this need its possible to do it yourself.

Example, right after connect

stty erase ^?

That sets the erase sequence to backspace.

I would think the arrow keys can be set in a smilar fashion, though its vi and I like the standard keyboard layout, or at least I'm used to it.

SEP
Steven E Protter
Owner of ISN Corporation
http://isnamerica.com
http://hpuxconsulting.com
Sponsor: http://hpux.ws
Twitter: http://twitter.com/hpuxlinux
Founder http://newdatacloud.com
Bill Hassell
Honored Contributor

Re: use of arrow buttons in vi editor

Actually, the arrow keys are not part of the ASCII character set (along with Home and End and Page Up, etc). So these keys (when enabled to transmit multi-letter codes) must be trapped by vi as an alias to the 'normal' vi commands. This is handled by a special file called .exrc and consists of mapping connections between characters and vi commands. For instance, with an HP terminal emulator, the End key will send ESC F so the .exrc file (for HP terminals) has ESC F mapped to the letter G. An example can be found in /usr/newconfig/etc/skel/.exrc (which only works with HP terminals).

So .exrc must be completely rewritten for every terminal type. An HP terminal is very different from a Wyse or VT100, so you'll need to follow these steps:

1. Identify the terminal emulation you are using (ie, yyse30, vt220, ansi, etc). The easiest is to ask the terminal itself with ttytype -s

2. Get a copy of the emulator's tech reference manual and determine if the arrow keys are functional. If they are (and remember that the arrow keys are PC keys that must be seen by your emulator and then something generated by the emulator when the key is pressed) then you'll need a list of the keys and codes. An alternative is to ask HP's terminfo database with the untic command (see below).

3. From the keys and codes, create a new .exrc file with the appropriate map. For example, the up-arrow key for a VT100 terminal emulator should generate ESC [ A while an HP terminal generates ESC A.

Now an easy way to get the map is to use the untic command along with the man page for terminfo. Start by getting a list of codes based on your terminal:

untic $(ttytype)

Print this list, then look up the curses code for the keys you want to map. For instance, the up-arrow key is called cuu1 in the curses capname. Find cuu1 in the untic list and there is the corresponding code generated by the up-arrow key. The ESC code is represented by \E.

Here's a starting point - be sure to "Save Link" since this is a binary file with embedded escape codes and Unix file line terminators: http://examples.oreilly.com/upt2/split/exrc

This file will need some editing based on your needs and terminal emulator.


Bill Hassell, sysadmin
pb raju
Occasional Contributor

Re: use of arrow buttons in vi editor

Hi ,

Thanks for the information.
The output of untic $(ttytype)..

#untic $(ttytype)
TERM = (hp)
hp|hpex|hewlett-packard extended capabilities,
am, xhp, da, db, mir,
cols#80, lines#24, lm#0, xmc#0, nlab#8, lh#2, lw#8,
bel=^G, cr=\r, tbc=\E3, clear=\E&a0y0C\EJ,
el=\EK, ed=\EJ, hpa=\E&a%p1%dC, cup=\E&a%p1%dy%p2%dC,
cud1=\EB, home=\E&a0y0C, cub1=\b, cuf1=\EC,
cuu1=\EA, dch1=\EP, dl1=\EM, smir=\EQ,
smso=\E&dB, smul=\E&dD, sgr0=\E&d@, rmir=\ER,
rmso=\E&d@, rmul=\E&d@, il1=\EL, kbs=\b,
ktbc=\E3, kclr=\EJ, kctab=\E2, kdch1=\EP,
kdl1=\EM, kcud1=\EB, krmir=\ER, kel=\EK,
ked=\EJ, kf1=\Ep, kf2=\Eq, kf3=\Er,
kf4=\Es, kf5=\Et, kf6=\Eu, kf7=\Ev,
kf8=\Ew, khome=\Eh, kich


From the output the arrow keys have the following keys :
1) left-arrow = cub1 , code generated is \b
2)right-arrow = cuf1 , code generated is \EC
3)up-arrow =cuu1 , code generated is \EA
4)down-arrow = cud1 , code generated is \EB

I have tried to map in .exrc without success.
How to map the above in .exrc file ?

Regards
Raju
Bill Hassell
Honored Contributor

Re: use of arrow buttons in vi editor

Since the terminal you are using (based on the utput of ttytype) is an HP terminal, just copy the HP file to your $HOME directory:

cp /usr/newconfig/etc/skel/.exrc $HOME/.exrc

Then run vi and the arrow keys should work fine. The arrow keys need to be mapped for use in insert mode too and the newconfig file has these listed.


Bill Hassell, sysadmin
pb raju
Occasional Contributor

Re: use of arrow buttons in vi editor

Hi ,

I have copied the hp file to $HOME directory.
Still I can't use the arrow key buttons.

View our .exrc file :

-------------------------------------------
set autoindent autowrite showmatch wrapmargin=0 report=1
map ^W :set wrapmargin=8
map ^X {!}sort -b
map ^[h 1G
map ^[H 1G
map ^[F G
map ^[V ^B
map ^[U ^F
map ^[T ^Yk
map ^[S ^Ej
map ^[Q i
map ^[P x
map ^[L O
map ^[M dd
map ^[K D
map ^[J DjdG$
map! ^[A ^[ka
map! ^[D ^[ha
map! ^[C ^[la
map! ^[B ^[ja
map! ^[L ^M
map! ^[Q ^[
map! ^[R ^[
---------------------------------

Regards
Raju
paolo barila
Valued Contributor

Re: use of arrow buttons in vi editor

Hi,
is there a way to set vi options in the "shell vi" set -o vi,
to use, for example, cursors to navigate the command history?
share share share
Bill Hassell
Honored Contributor
Solution

Re: use of arrow buttons in vi editor

That is the correct .exrc file so as long as you are using an HP terminal, they will work. Now if you are using a PC, the emulator is critical -- there are very few useful HP terminal emulators, the best is Reflection for HP (*not* Reflection/X) with QCTerm a useful free HP terminal emulator. What emulator are you using on your PC?


Bill Hassell, sysadmin
Dennis Handly
Acclaimed Contributor

Re: use of arrow buttons in vi editor

>paolo: is there a way to set vi options in the "shell vi" cursors to navigate the command history?

I don't think so. Possibley for emacs mode but I don't see any control chars for vi for ksh.

Basically you should not be using the arrow keys in vi, but the standard h, j, k l. These work in the shell and gdb.

I only use the arrow keys when I'm moving away from the home keys or using the mouse or looking at the screen.