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?
Asked by ring bearer on August 30, 2010.
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")
Answered by ring bearer on August 31, 2010.
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.
Answered by Dennis Williamson on August 30, 2010. Last Edited on August 31, 2010.
Content from Superuser of Stack Exchange. Original article at Superuser.
Thanks for the suggestion, However it is not working as expected. I added these to .profile and nothing happens. - ring bearer on August 30, 2010
@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 on August 30, 2010
No, I tried exactly that (echo "Hi") and did not see any output. - ring bearer on August 30, 2010
@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 on August 30, 2010
@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 on August 30, 2010
@ring bearer: I'm sorry, I just realized that I didn't say that the keystroke represented by `^[[A` shouldn't be a literal "caret-lbracket-lbracket-A" but it should be `Esc-lbracket-A`. You can insert an escape there (how you do that will depend on what editor you use) or you can use the method in my edited answer. Sorry again! - Dennis Williamson on August 31, 2010
@Dennis. trap did not work, rather, set -o emacs and a few aliases did - ring bearer on August 31, 2010