It's normal when using terminals that pressing up and down cycles through previous commands entered chronologically.
I learned from a site how to add to that behaviour by autocompleting what I'm typing at the cursor based on previously entered commands when pressing up and down.
For example, let's say I typed the following commands in this order:
ls Videos
ls Vids
lsomething
ls Videos/Funny/Old
vi file
ls Music
If I haven't typed anything, pressing up and down will cycle through all of the lines just like normal. But, if I've typed ls
, pressing up and down cycles through all commands where the first 2 characters are ls
(lines 1,2,3,4,6 above). Entering ls
(with a space after) though, will only let up and down cycle through lines 1,2,4,6. Similarly, ls Vid
lets the arrows cycle through lines 1,2,4 but ls Videos
just allows cycling between lines 1 and 4.
It's pretty useful to complete values specific to commands that you need to enter over and over again without having to cycle through every single unrelated command you've entered between them. For example, I'm trying to test the effects of env
values, like locale, on things:
env [many different values] [command]
[insert many different commands here]
env [slightly different values from before] [command]
[doing other stuff]
I'd only have to press up a few times after typing env
to cycle between the values I've tried.
I apologize if it's a bit of a long way to describe it. I don't know what it's called. My terminals used to have this behaviour, but they seem to have lost it and I can't find the site I learned it from. I think it has something to do with editing ~/.bashrc
.
To get the behavior you are after, add these lines to your
~/.inputrc
(create the file if it does not exist):Then, open a new terminal and it will work as expected. This behavior is controlled by the settings in
/etc/inputrc
and~/.inputrc
. You can read more about them in theReadline Command Names
section ofman bash
: