by thom_nic · 10y ago · 0 comments
# From http://www.ukuug.org/events/linux2003/papers/bash_tips/
# Incremental searching with Up and Down is configured in .inputrc
"\e[A": history-search-backward
"\e[B": history-search-forward
... so if I type `ssh <up arrow>` I get the last command that started with `ssh`, not the last command I ran. oh-my-zsh thankfully does this by default as well. But I still use my .inputrc on server boxen where I don't want/need to install a different default shell.Also worth noting that all of those `bind` commands in OP's script are actually .inputrc lines if you remove the `bind` and surrounding quotes.
If I'm trying to semantically query my history (for "ssh") in this case I'll use the ^R binding to incrementally search the history, or literally grep ~/.history for what I'm looking for.
That's not to say that you're "wrong", just that calling these things "sensible defaults" is sort of missing the point. Nothing about them is sensible for everyone.
Once you get used to it, the only downside of up/down history search is when you ever use a shell that doesn't do it and you feel lost.
"\e[5~": history-search-backward
"\e[6~": history-search-forward
This allows you to continue using arrows for absolute chronological history then use PageUp and PageDn for history search.You could also change it to
"\e[5~": history-substring-search-backward
"\e[6~": history-substring-search-forward
if you want to search for a string match anywhere in the command rather than at the beginning. It might be 'substr' rather than 'substring' depending on your Bash version.Obviously the utility of this depends on your keyboard layout and config, as much as it does on personal preferences.
You can see the full list of commands at https://www.gnu.org/software/bash/manual/html_node/Commands-....
It mostly helps when you type complicated command and after half an hour you need to repeat it for some reason. You type the command you used, and hit a arrow up.