Inputrc for bash history completion using up/down arrows

The bashrc file stores key mappings. Use your own bashrc by putting export INPUTRC=~/.inputrc in your .bash_profile or .bashrc

This page, Creating the /etc/inputrc File and this page, Super-useful inputrc give some useful advice about things you can put in those files.

One of things I most often find myself doing is searching my command line history. I frequently use the cursor up and down to scroll through my most recent commands. Often, I want to re-use a particular grep or find that I used recently, but I don't remember the specifics of it. With the text below in your .inputrc, you can type in the first few letters, say gr or f and press the cursor keys and it will scroll through your command history, showing the commands that began with those characters. Nice. :)

# By default up/down are bound to previous-history
# and next-history respectively. The following does the
# same but gives the extra functionality where if you
# type any text (or more accurately, if there is any text
# between the start of the line and the cursor),
# the subset of the history starting with that text
# is searched (like 4dos for e.g.).
# Note to get rid of a line just Ctrl-C
"\e[B": history-search-forward
"\e[A": history-search-backward

$if Bash
  # F10 toggles mc on and off
  # Note Ctrl-o toggles panes on and off in mc
  "\e[21~": "mc\C-M"

  #do history expansion when space entered
  Space: magic-space
$endif

# Include system wide settings which are ignored
# by default if one has their own .inputrc
$include /etc/inputrc

Source: Inputrc for bash history completion using up/down arrows

Popular Posts