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?
2 Answers
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")
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.
-
Thanks for the suggestion, However it is not working as expected. I added these to .profile and nothing happens. Aug 30, 2010 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 addecho "HI!"
to the function, does "HI!" get output with every keypress? Aug 30, 2010 at 19:32 -
No, I tried exactly that (echo "Hi") and did not see any output. Aug 30, 2010 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.) Aug 30, 2010 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 Aug 30, 2010 at 21:19