Super-useful inputrc

You either want to place the following in ~/.inputrc or /etc/inputrc… I’ve found that while ~/.inputrc works sometimes, it doesn’t on all systems.


"\e[1~": beginning-of-line
"\e[4~": end-of-line
"\e[5~": beginning-of-history
"\e[6~": end-of-history
"\e[3~": delete-char
"\e[2~": quoted-insert
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
set completion-ignore-case On

All lines except the last enable nice readline & bash cursor movement (control + arrow keys and what not) while the last line turns on case insensitivity for tab-completion, enabling you to have folders and files of mixed case characters while not having to type the capital letters. (You can have a directory called “Documents” and tab-complete by tying “doc<tab>

I’ve been enjoying the above for a while now, and I think it really should be the default settings for distributions.

Note: This works for Linux, Mac OS X, and *BSD. It might work for people using Bash on Windows, but you’re on your own there. (:

Tags: , ,

30 Responses to “Super-useful inputrc”

  1. With one change that’s a very nice default configuration.

    “\e[5~”: history-search-backward
    “\e[6~”: history-search-forward

    This maps Page Up / Page Down to the IMO very useful history search function. Configured like that by default in paldo.

  2. If ~/.inputrc doesn’t work, then you need to add

    export INPUTRC=~/.inputrc

    to your .bashrc/.bash_profile/wherever.

  3. Marius, thanks for the tip!

  4. Colin Marquardt says:

    These should all be “quote-backslash-e…”, right? The backslash is missing for me.

    I have a few more variables set:

    set bell-style visible
    set expand-tilde on
    set convert-meta off
    set input-meta on
    set output-meta on
    set show-all-if-ambiguous on
    set visible-stats on

  5. Colin Marquardt says:

    FWIW, the error is

    faultCode0faultStringFatal error:Cannot access empty property in /home/garrett/sites/linuxart.com/site/log/wp-content/plugins/SK2/sk2_comment_class.php on line 154

  6. Jimmy says:

    Yes, finally! I’ve been looking for this. Well, not that active lately, but it’s been in my mind to fix this. Thanks!

  7. I acutally go the whole hog and do like 4dos used to.
    I.E. have the up/down arrows do the search.
    Note if you don’t type anything the up/down arrow behave as before.
    http://www.pixelbeat.org/settings/.inputrc

  8. Wouter says:

    Yes you need to escape with a \\ before the first e. Doesn’t seem to work in my xterm (debian) though.. :(

  9. Wouter says:

    Yes you need to escape with a ‘\’ before the first e. Doesn’t seem to work in my xterm (debian) though.. :(

  10. Anonymous says:

    Works great in gnome-terminal; thanks!

    I also tried to get Control-Backspace to do unix-filename-rubout, but unfortunately it seems that Control-Backspace doesn’t look any differently from Backspace.

  11. [...] Super-useful inputrc enables you to CTRL-left and CTRL-right through your current command line, just like in the good ol’ DOS days! [...]

  12. Francesco says:

    for those who like the WinNT/XP way TAB works in MSDOS prompts (i.e. instead of showing a list of possible completions like bash does on default, TAB cycles through possible completions), just add this to .inputrc:

    “\t”: menu-complete

    it saves me a lot of typing !!

  13. Jason says:

    Anybody know how to make a shortcut so that way when i press “ctrl+a” or whatever letter, i can set it to do an action…i was told it was with the /etc/inputrc file, but i can’t figure it out.

  14. ameet says:

    how to make readline auto compleate search the words to be compleated from the file.

  15. Triffid Hunter says:

    I had to add:
    “\e[1;5C”: forward-word
    “\e[1;5D”: backward-word
    on my (gentoo linux) system for word search to work. A similar translation should apply nicely to the others.

  16. micha says:

    I noticed what appears to be a bug in readline. I’m using Terminal.app on tiger with bash, and doing ‘set completion-ignore-case On’ causes completion to break with directories that have spaces in the name. For example:

    /home/micha/Documents/My Stuff/myfile.pdf

    If, from /home/micha I do

    ls documents/my\ [TAB]

    it completes correctly to produce Documents/My\ Stuff/ but if I press tab again at that point it produces this:

    ls Documents/My\\\ Stuff

    which is wrong.

  17. nix says:

    One simple question:

    How does the keyseq get generated? Are they predefined values? Do they relate to the ansi key set?

    IE: “\e[3~”: delete-char
    How does the value: “\e[3~”: relate to the delete key?

  18. Will says:

    Q: How does the value: “\e[3~”: relate to the delete key?

    A: “\e[3~” is the sequence of bytes that your terminal sends when the delete key is pressed. And when I say “terminal”, I mean either a real serial terminal, or an xterm-like thing, or the Linux console driver.

  19. kortina says:

    Does this work with iterm in os x? I copied and pasted

    “\e[1~”: beginning-of-line
    “\e[4~”: end-of-line
    “\e[5~”: beginning-of-history
    “\e[6~”: end-of-history
    “\e[3~”: delete-char
    “\e[2~”: quoted-insert
    “\e[5C”: forward-word
    “\e[5D”: backward-word
    “\e\e[C”: forward-word
    “\e\e[D”: backward-word

    into my ~/.inputrc and tried doing export INPUTRC=~/.inputrc but forward and backword word do not work for me. Anyone got any suggestions?

  20. Bryan Harris says:

    Hi,

    I think there is a man page, or an info page, or some kind of document in my system somewhere which tells me how the escape sequences work. Does anybody know where that file is at? I am using Slackware 12.0, and I thought I had seen that file before.

  21. omega says:

    kortina: if you typed “export INPUTRC=~/.inputrc” into your terminal that just sets the variable, doesn’t actually read the file. you either have to type it in your ~/.bash_profile or just put those settings in /etc/inputrc instead of locally.

    oh, i’m not sure about if it works with iterm, i just use the Terminal in leopard (works just fine for me, i’ve yet to find something that iterm does and Terminal doesn’t – besides fullscreening which i don’t like anyway)

    but yes, it does work with mac os x :)

  22. Rich says:

    Whoops. Looks like somebody’s blog is converting double quote characters into posh quotes. Notice how there’s a difference between “these quotes” and "these"

  23. kwilliam says:

    Thank you blog author and Marius Gedminas!
    After much fruitless searching, I have finally gotten the console to use a visible bell instead of beeping loudly.

    I added line
    set bell-style visible
    to ~/.inputrc
    and added line
    export INPUTRC=~/.inputrc
    to ~/.bashrc

  24. Binny V A says:

    Thanks for this post. If possible, can you and some comments to show which keys you are using? I know [5~, [6~ is Page up/Page down – but the rest have me a bit confused.

  25. andre says:

    Debian has a file explaining this:

    /usr/share/doc/bash/inputrc.arrows:
    # This file controls the behaviour of line input editing for
    # programs that use the Gnu Readline library.
    #
    # Arrow keys in keypad mode
    #
    “\C-[OD” backward-char
    “\C-[OC” forward-char
    “\C-[OA” previous-history
    “\C-[OB” next-history
    #
    # Arrow keys in ANSI mode
    #
    “\C-[[D” backward-char
    “\C-[[C” forward-char
    “\C-[[A” previous-history
    “\C-[[B” next-history
    #
    # Arrow keys in 8 bit keypad mode
    #
    “\C-M-OD” backward-char
    “\C-M-OC” forward-char
    “\C-M-OA” previous-history
    “\C-M-OB” next-history
    #
    # Arrow keys in 8 bit ANSI mode
    #
    “\C-M-[D” backward-char
    “\C-M-[C” forward-char
    “\C-M-[A” previous-history
    “\C-M-[B” next-history

  26. [...] ##helpful sites#http://codesnippets.joyent.com/tag/inputrc#http://linuxart.com/log/archives/2005/10/13/super-useful-inputrc/———————————–EOF [...]

  27. Ryan says:

    You don’t need to read docs to find the key codes. Just use “showkey -a”.

  28. Anonymous says:

    HELP! =) how do i discover the symbols that represent key combinations like
    shift+d

  29. [...] Linux initrc file page shows a common initrc for Linux, and Garrett LeSage writes about a few super-useful inputrc [...]

  30. Jim says:

    On osx use the read command to figure out your keys, for control+left-arrow I get “^[[1;5D” and then use “”\e[1;5D” in my inputrc. See ‘man bash’ for the various escape sequences and functions if you need more info.

Leave a Reply