Autocompletion
How to Enable History Search in the Terminal
When working in a terminal, navigating through command history efficiently can save time. By modifying the .inputrc
file or .bashrc
, you can enable a feature that allows you to search command history using the arrow keys.
Step 1: Modify the .inputrc
File
.inputrc
FileRun the following command to append the necessary configuration to your ~/.inputrc
file:
cat >> ~/.inputrc <<'EOF'
"\e[A": history-search-backward
"\e[B": history-search-forward
set show-all-if-ambiguous on
set completion-ignore-case on
EOF
Explanation:
\e[A
and\e[B
correspond to the Up and Down arrow keys.history-search-backward
allows searching for commands in history that match the current input when pressing the Up arrow.history-search-forward
does the same but moves forward in history when pressing the Down arrow.
Step 2: Apply the Changes
To apply the changes, either open a new shell session or reload the .inputrc
file manually:
bind -f ~/.inputrc
Step 3: Test the Feature
Open a new terminal session.
Type a few characters of a previously executed command.
Press the Up arrow (
↑
) to cycle through past commands that match your input.Press the Down arrow (
↓
) to move forward in the search.
Last updated