Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.3: Assign arrow keys to history search in bash UNIX
With Panther, the default shell is now Bash. I had customized my tcsh shell using this hint In bash you can get similar results by adding this to your .bash_profile
bind '"M-[A":history-search-backward'
bind '"M-[B":history-search-forward'
where M-[A is the up key and M-[B is the down key.
    •    
  • Currently 2.33 / 5
  You rated: 5 / 5 (9 votes cast)
 
[23,529 views]  

10.3: Assign arrow keys to history search in bash | 9 comments | Create New Account
Click here to return to the '10.3: Assign arrow keys to history search in bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.3: Assign arrow keys to history search in bash
Authored by: chinstrap on Oct 30, '03 11:30:49AM
Or, you could just do nothing at all since this is bash's default behaviour.

[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: krykertano on Oct 30, '03 12:53:39PM

Actually, bash's default behavior is to bind the up and down arrows to previous-history and next-history, not history-search-backward and history-search-forward.

If you're going to make snide remarks, I suggest you actually try the hint first before you open your mouth.



[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: mithras on Oct 30, '03 01:58:11PM
I accomplished this with
"\e[A": history-search-backward
"\e[B": history-search-forward

in my .inputrc. I think that's essentially equivalent.

PS, don't forget to add these to your .inputrc while you're at it:
set show-all-if-ambiguous on
set completion-ignore-case on


---
--
Listen To My iTunes Library (6500+ songs, iTunes 4 required)

[ Reply to This | # ]

10.3: Assign arrow keys to history search in bash
Authored by: rootpoot on Oct 30, '03 03:11:29PM

I'd like to bind option-up and option-down to history-search-backward and history-search-forward, respectively, but can't figure out how.

The readline man page leads me to believe I could use \M-[A. but this doesn't work.



[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: watson on Oct 31, '03 01:05:27PM

Hmm, did you try \\M-[A to protect the shell of interpreting the backslash? Or '\M-[A' ?

Just my .02,
Henrik



[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: morgion on Nov 07, '03 10:57:08PM

I haven't been able to get this to work; i've added it to .bash_profile, opened new terminals, quit Terminal, and still no go.

Do I need a specific terminal type in Preferences? Or some setting in emulation?



[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: miggins on Dec 09, '03 04:59:45PM
I could not get the suggestions here to work, I ended up doing the following.
Type this into vi ~/.bash_profile, and in place of
<up>
type control + v, then up arrow. In place of
<down>
type control + v then down arrow. (Control V tells vi to put the next character in the doc, rather than just moving up when you press up arrow etc.)

bind '"<up>":history-search-backward'
bind '"<down>":history-search-forward'
Then close all Terminal windows, and quit the app, then open Terminal again and you should have the feature.

[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: inca on May 25, '04 01:34:24PM

I had to use:

bind '"\M-[A":history-search-backward'
bind '"\M-[B":history-search-forward'



[ Reply to This | # ]
10.3: Assign arrow keys to history search in bash
Authored by: Lri on Jun 11, '12 02:57:31AM

I've assigned the commands to ⌥↑ and ⌥↓ instead. If you want the shortcuts to be available in other shells and programs, you can add them to ~/.inputrc (which is used to configure the same Readline keybindings and settings that can be set with the bind builtin).

"\M-\e[A": history-search-backward
"\M-\e[B": history-search-forward
Edited on Jun 11, '12 02:57:49AM by Lri


[ Reply to This | # ]