Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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 want to map my Up/Down arrow keys in bash to Alt+j/Alt+k as I don't want to move my hands to the arrow keys when I choose previously executed commands using Up/Down arrow keys.

Using vi mode in bash is not an option because I don't want to press Esc every now and then while using bash. (as I am not accustomed to doing that)

share|improve this question
up vote 4 down vote accepted

Add the following to your ~/.inputrc file, creating it if it doesn't exist:

"\ej": previous-history
"\ek": next-history

This will map Alt-j to previous-history and Alt-k to next-history.

Note that by default these are mapped to Ctrl-p and Ctrl-n anyway.

share|improve this answer
Ok, this is one way of achieving what I want. Now that I know about this, I would like to know how can I remap Ctrl-p & Ctrl-n to history-search-backward and history-search-forward. – Abhijeet Rastogi Aug 14 '12 at 10:21
@shadyabhi By applying what you learned from this answer. Hint: "\C-p" – Daniel Beck Aug 14 '12 at 10:22
Where can I see the documentation of the syntax for defining bindings? Googling for "bash bind documentation" didn't take me the official doc. – Abhijeet Rastogi Aug 14 '12 at 10:26
@shadyabhi It's in section 8.3.1 of the manual I linked to, with examples in 8.3.3. – Daniel Beck Aug 14 '12 at 10:28

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.