Following the instructions here, I edited by .bash_profile to enable the up and down arrows to autocomplete what I have typed in the shell based on previous commands.
I added to my .bash_profile:
# bind history search to up and down arrows
if [[ $- == *i* ]]
then
bind '"\e[A": history-search-backward'
bind '"\e[B": history-search-forward'
fi
This is great, but I want the down arrow to return to my original text if I can't find the command I'm looking for.
For example, say I have three previous commands:
ls -l
ls -al
Now, I type ls
with the intention of autocompleting it to ls -a
.
I hit the up arrow, which (with my current implementation) autocompletes my text to ls -al
. I hit the up arrow again, which autocompletes my text to ls -l
. At this point, I decide that I won't find the command I'm looking for. If I press the down arrow, the text changes to ls -al
, but pressing the down arrow again doesn't change anything. I want pressing the down arrow to return to my original text (ls
in this case) after I've reached the most recent command in the history.
I would really appreciate it if anyone could help me out or point me in the right direction.
Thanks!
Best Answer
Ctrl+K
will kill the text from the cursor to the end of line. so If you haven't moved the cursor,Ctrl+K
will give you (ie, effectively revert to) your original text