On the bash
command-line, ↑ gives me the previous command. On the command-lines in ipython
or matlab
, when I type a few characters, ↑ gives me the previously entered command starting with those characters. How can I enable exactly this behaviour in bash
?
I am aware of more advanced ways of searching through the command-line history, but sometimes a simple way is more convenient.
Best Answer
The readline commands that you are looking for are the
history-search-*
commands:Binding these in your
.inputrc
, like so:will allow you to enter the first characters of a command, and then use the Up and Down keys to move through only those commands in your
.bash_history
that begin with that string.For example, entering
vi
and the Up would take you to the first previous command beginning withvi
, likevim somefile
. Entering Up would take you to the next previous instance, and so on.You can read more about all of the readline bindings here: http://linux.about.com/library/cmd/blcmdl3_readline.htm