Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know about set -o vi and k and j combinations. I want to map these to up arrow and down arrow so that I can use AIX(ksh prompt) just like bash . Any suggestions?

share|improve this question
up vote 2 down vote accepted

Here is one way that worked for me: Put the following in to .profile script

set -o emacs
alias __A=$(print -n "\020")
alias __B=$(print -n "\016")
alias __C=$(print -n "\006")
alias __D=$(print -n "\002")
share|improve this answer

You may be able to write a trap on the KEYBD signal that will process the arrow keystrokes and issue the vi k and j keystrokes in their place.

You can find out what characters are emitted by your arrow keys by pressing Ctrl-v then the key. You should see something like ^[[A.

For example:

f () { if [[ ${.sh.edchar} == $'\033[A' ]]; then .sh.edchar="k"; fi; }
trap f KEYBD

Test the .sh.edmode variable to control whether the key is substituted in insert or command mode (its value will be 0x1b while in insert mode and null otherwise.

share|improve this answer
Thanks for the suggestion, However it is not working as expected. I added these to .profile and nothing happens. – ring bearer Aug 30 '10 at 18:56
@ring bearer: At a ksh prompt in insert mode (in vi mode) or in emacs mode, press Ctrl-v then up-arrow. Does that give you ^[[A? If you add echo "HI!" to the function, does "HI!" get output with every keypress? – Dennis Williamson Aug 30 '10 at 19:32
No, I tried exactly that (echo "Hi") and did not see any output. – ring bearer Aug 30 '10 at 19:37
@ring bearer: If you execute the function (with the echo) from the command line, do you see "HI!"? If not, then you need to source your .profile or exit and restart the shell. (By the way, I assume that you did that, but I'm compelled to be thorough.) – Dennis Williamson Aug 30 '10 at 20:31
@Dennis, thanks. However I do not see "Hi" or any previous command appear on the prompt - not sure what is wrong; Up arrow prints ^[[A with CTRL + V – ring bearer Aug 30 '10 at 21:19

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .