Context specific history at the bash prompt
One change I made recently to my .profile is this:
# up & down map to history search once a command has been started. bind '"\e[A":history-search-backward' bind '"\e[B":history-search-forward'
These two bind command change the way that the up and down arrow keys work once you start typing a command to only search the history for lines that start with what you’ve typed so far.
This means that I type, say, git and then press ↑ & ↓ to go through all the times I’ve typed a git command without having to go through all the other commands.
It’s quite handy and I find it easier to use than ctrl+r.
Awesome. But bind doesn't work in zsh I found. zsh users can use:
to achieve the same.
Thanks Joshua!
You can also do this with a .inputrc file, along with making it case insensitive and provide a list the possible completion values. The I got this from a post by Jude Robinson here on coderwall.com
I prefer to map this to Shift+Up (
"\e[1;2A"
) instead, because when I work with other people, they were getting confused by the way the Up arrow was working. Some terminal emulators come with Shift+Up defined, but on Mac OS X Terminal, I had to define it in the Terminal preferences. (Actually, I've scripted the keybindings, but it was a lot of work: https://github.com/boochtek/mac_config/blob/master/terminal.sh)It's worth checking
/etc/inputrc
on your system, as there are usually suggestions in there that can make working in the terminal more pleasant.I like using:
"\e[5~": history-search-backward
"\e[6~": history-search-forward
which make Page Up and Page Down search through the history, instead of ↑ and ↓ as you describe. These are enabled by default nowadays on Fedora (see https://bugzilla.redhat.com/show_bug.cgi?id=500989).