Softpanorama

May the source be with you, but remember the KISS principle ;-)
Home Switchboard Unix Administration Red Hat TCP/IP Networks Neoliberalism Toxic Managers
(slightly skeptical) Educational society promoting "Back to basics" movement against IT overcomplexity and  bastardization of classic Unix

Using inputrc for key remapping

Customizing keystrokes

The keystrokes you type at a terminal session, and also those used in programs such as FTP, are processed by the readline library and can be configured. By default, the customization file is .inputrc in your home directory, which will be read during bash startup if it exists. You can configure a different file by setting the INPUTRC variable. If it is not set, .inputrc in your home directory will be used. Many systems have a default key mapping in /etc/inputrc, so you will normally want to include these using the $include directive.

for example you can bind your ls -lt to the Ctrl-t key combination (press and hold Ctrl, then press t). If you want the command to be executed with no parameters, add \n to the end of the configuration line.

Sample .inputrc file
                    
# My custom key mappings
$include /etc/inputrc

You can force the INPUTRC file to be re-read again by pressing Ctrl-x then Ctrl-r. Note that some distributions will set INPUTRC=/etc/inputrc if you do not have your own .inputrc, so if you create one on such a system, you will need to log out and log back in to pick up your new definitions. Just resetting INPUTRC to null or to point to your new file will reread the original file, not the new specification.

The INPUTRC file can include conditional specifications. For example, the behavior of your keyboard should be different according to whether you are using emacs editing mode (the bash default) or vi mode. See the man pages for bash for more details on how to customize your keyboard.


Think of this as a brief FUQ (a veritable 'Quickie', as
it were) -- Frequently Unanswered Questions

Disclaimer/Alibi
----------------
These are really questions for the 'bash' group, except
that they specifically deal with the PC and its
keyboard (*and* I'm using 'bash' on Cygwin).

I've searched for answers throughout the Cygwin,
'emacs' and 'bash' documentation, and the Web and even
bought the book, /Learning the bash shell/. Alas, no
FUQing help! ;-)

I plan to document this in some copylefted docs, so you
should be able to leverage the time of your answers.

Q1 -- When you remap a 'bash' Edit Mode function in
.inputrc, it looks like this:

"\e[3~":      delete-char # DEL key

The entity in double quotes ("\e[3~"), I'm calling the
"key ID (KID)". In the above '.inputrc' declaration,
the function 'delete-char' being remapped from its
default key assignment to the KID -- "\e[3~" -- the
<DEL> key.

What are the KIDs of the following IBM PC keys
(specified below with facsimiles of the key caps
contained in angle brackets -- '<...>')?

Cursor control key pad
----------------------
<HOME>
<END>
<left-arrow>
<right-arrow>
<PAGE_UP>
<PAGE_DOWN>
<INSERT>

Numeric pad
-----------
<->
<+>
<ENTER>
</>

In general, I'd like a table that maps the KIDs for all
104 keys on the keyboard I use. Or, better still, is
there a way to use scan codes?

(Incidentally, what makes finding a table of these
KIDs so difficult is the failure of the documentation
to assign this concept a unique, or even a consistent
word.)

Q2
--

Is there a way to make the <INSERT> key a toggle
between the insert and overwrite modes of 'bash'
edit mode?

I used to have these figured out for 'Microemacs', but
that was half a lifetime ago, for me, and Microemacs
supported scan codes, if I remember correctly.

The discerning reader will have surmised both from
these questions and my earlier query 'on the humble
<DEL> key', that I am trying to make a PC, under the
estimable Cygwin, exploit those few niceties of the PC
(keyboard).

Thanks

Lee

P.S. In anticipation of the "righteous" among you being
     offended by the term 'FUQ', I shared your
     indignation; it occurred shortly after buying the
     ill-fated -- and referenced -- 'bash' book. (Yes,
     it's true; I'm bashing the 'bash' book.)

     And, please, whatever you do, don't kid a KIDer. ;-)


Lee D. Rothstein -- [email protected]
VeriTech -- 603-424-2900
7 Merry Meeting Drive
Merrimack, NH 03054-2934

----------

problems with certain entries in .inputrc


I'm using Cygwin 1.1.7 for Win95x:

BUG: If I include the following line in my .inputrc file, then no bindings
get loaded when the shell starts:

"Û": self-insert

(the above is ascii value 219)

what is wierd is that all other binding directives work fine.

This is the contents of my .inputrc file.  You'll notice that I commented
out the trouble line - when I do this, all bindings work fine.  However, if
I uncomment this line, then none of my bindings work:

"\C-g": abort
"\C-x\C-g": abort
"\e\C-g": abort
"\C-j": accept-line
"\C-m": accept-line
# alias-expand-line (not bound)
# arrow-key-prefix (not bound)
"\C-b": backward-char
"\eOD": backward-char
"\e[D": backward-char
"\C-h": backward-delete-char
"\C-?": backward-delete-char
"\C-x\C-?": backward-kill-line
"\e\C-h": backward-kill-word
"\e\C-?": backward-kill-word
"\eb": backward-word
"\e<": beginning-of-history
"\C-a": beginning-of-line
"\e[1~": beginning-of-line
"\C-xe": call-last-kbd-macro
"\ec": capitalize-word
"\C-]": character-search
"\e\C-]": character-search-backward
"\C-l": clear-screen
"\C-i": complete
"\e\C-[": complete
"\e!": complete-command
"\e/": complete-filename
"\e@": complete-hostname
"\e{": complete-into-braces
"\e~": complete-username
"\e$": complete-variable
# copy-backward-word (not bound)
# copy-forward-word (not bound)
# copy-region-as-kill (not bound)
"\C-d": delete-char
# delete-char-or-list (not bound)
"\e\\": delete-horizontal-space
"\e-": digit-argument
"\e0": digit-argument
"\e1": digit-argument
"\e2": digit-argument
"\e3": digit-argument
"\e4": digit-argument
"\e5": digit-argument
"\e6": digit-argument
"\e7": digit-argument
"\e8": digit-argument
"\e9": digit-argument
"\C-x\C-v": display-shell-version
"\C-xA": do-lowercase-version
"\C-xB": do-lowercase-version
"\C-xC": do-lowercase-version
"\C-xD": do-lowercase-version
"\C-xE": do-lowercase-version
"\C-xF": do-lowercase-version
"\C-xG": do-lowercase-version
"\C-xH": do-lowercase-version
"\C-xI": do-lowercase-version
"\C-xJ": do-lowercase-version
"\C-xK": do-lowercase-version
"\C-xL": do-lowercase-version
"\C-xM": do-lowercase-version
"\C-xN": do-lowercase-version
"\C-xO": do-lowercase-version
"\C-xP": do-lowercase-version
"\C-xQ": do-lowercase-version
"\C-xR": do-lowercase-version
"\C-xS": do-lowercase-version
"\C-xT": do-lowercase-version
"\C-xU": do-lowercase-version
"\C-xV": do-lowercase-version
"\C-xW": do-lowercase-version
"\C-xX": do-lowercase-version
"\C-xY": do-lowercase-version
"\C-xZ": do-lowercase-version
"\eA": do-lowercase-version
"\eB": do-lowercase-version
"\eC": do-lowercase-version
"\eD": do-lowercase-version
"\eE": do-lowercase-version
"\eF": do-lowercase-version
"\eG": do-lowercase-version
"\eH": do-lowercase-version
"\eI": do-lowercase-version
"\eJ": do-lowercase-version
"\eK": do-lowercase-version
"\eL": do-lowercase-version
"\eM": do-lowercase-version
"\eN": do-lowercase-version
"\eOE": do-lowercase-version
"\eOF": do-lowercase-version
"\eOG": do-lowercase-version
"\eOH": do-lowercase-version
"\eOI": do-lowercase-version
"\eOJ": do-lowercase-version
"\eOK": do-lowercase-version
"\eOL": do-lowercase-version
"\eOM": do-lowercase-version
"\eON": do-lowercase-version
"\eOO": do-lowercase-version
"\eOP": do-lowercase-version
"\eOQ": do-lowercase-version
"\eOR": do-lowercase-version
"\eOS": do-lowercase-version
"\eOT": do-lowercase-version
"\eOU": do-lowercase-version
"\eOV": do-lowercase-version
"\eOW": do-lowercase-version
"\eOX": do-lowercase-version
"\eOY": do-lowercase-version
"\eOZ": do-lowercase-version
"\eP": do-lowercase-version
"\eQ": do-lowercase-version
"\eR": do-lowercase-version
"\eS": do-lowercase-version
"\eT": do-lowercase-version
"\eU": do-lowercase-version
"\eV": do-lowercase-version
"\eW": do-lowercase-version
"\eX": do-lowercase-version
"\eY": do-lowercase-version
"\eZ": do-lowercase-version
"\e[1A": do-lowercase-version
"\e[1B": do-lowercase-version
"\e[1C": do-lowercase-version
"\e[1D": do-lowercase-version
"\e[1E": do-lowercase-version
"\e[1F": do-lowercase-version
"\e[1G": do-lowercase-version
"\e[1H": do-lowercase-version
"\e[1I": do-lowercase-version
"\e[1J": do-lowercase-version
"\e[1K": do-lowercase-version
"\e[1L": do-lowercase-version
"\e[1M": do-lowercase-version
"\e[1N": do-lowercase-version
"\e[1O": do-lowercase-version
"\e[1P": do-lowercase-version
"\e[1Q": do-lowercase-version
"\e[1R": do-lowercase-version
"\e[1S": do-lowercase-version
"\e[1T": do-lowercase-version
"\e[1U": do-lowercase-version
"\e[1V": do-lowercase-version
"\e[1W": do-lowercase-version
"\e[1X": do-lowercase-version
"\e[1Y": do-lowercase-version
"\e[1Z": do-lowercase-version
"\e[4A": do-lowercase-version
"\e[4B": do-lowercase-version
"\e[4C": do-lowercase-version
"\e[4D": do-lowercase-version
"\e[4E": do-lowercase-version
"\e[4F": do-lowercase-version
"\e[4G": do-lowercase-version
"\e[4H": do-lowercase-version
"\e[4I": do-lowercase-version
"\e[4J": do-lowercase-version
"\e[4K": do-lowercase-version
"\e[4L": do-lowercase-version
"\e[4M": do-lowercase-version
"\e[4N": do-lowercase-version
"\e[4O": do-lowercase-version
"\e[4P": do-lowercase-version
"\e[4Q": do-lowercase-version
"\e[4R": do-lowercase-version
"\e[4S": do-lowercase-version
"\e[4T": do-lowercase-version
"\e[4U": do-lowercase-version
"\e[4V": do-lowercase-version
"\e[4W": do-lowercase-version
"\e[4X": do-lowercase-version
"\e[4Y": do-lowercase-version
"\e[4Z": do-lowercase-version
"\e[E": do-lowercase-version
"\e[F": do-lowercase-version
"\e[G": do-lowercase-version
"\e[H": do-lowercase-version
"\e[I": do-lowercase-version
"\e[J": do-lowercase-version
"\e[K": do-lowercase-version
"\e[L": do-lowercase-version
"\e[M": do-lowercase-version
"\e[N": do-lowercase-version
"\e[O": do-lowercase-version
"\e[P": do-lowercase-version
"\e[Q": do-lowercase-version
"\e[R": do-lowercase-version
"\e[S": do-lowercase-version
"\e[T": do-lowercase-version
"\e[U": do-lowercase-version
"\e[V": do-lowercase-version
"\e[W": do-lowercase-version
"\e[X": do-lowercase-version
"\e[Y": do-lowercase-version
"\e[Z": do-lowercase-version
"\el": downcase-word
# dump-functions (not bound)
# dump-macros (not bound)
# dump-variables (not bound)
"\e\C-i": dynamic-complete-history
# emacs-editing-mode (not bound)
"\C-x)": end-kbd-macro
"\e>": end-of-history
"\C-e": end-of-line
"\e[4~": end-of-line
"\C-x\C-x": exchange-point-and-mark
# forward-backward-delete-char (not bound)
"\C-f": forward-char
"\eOC": forward-char
"\e[C": forward-char
"\C-s": forward-search-history
"\ef": forward-word
"\C-x*": glob-expand-word
"\C-xg": glob-list-expansions
# history-and-alias-expand-line (not bound)
"\e^": history-expand-line
# history-search-backward (not bound)
# history-search-forward (not bound)
"\e#": insert-comment
"\e*": insert-completions
"\e.": insert-last-argument
"\e_": insert-last-argument
"\C-k": kill-line
# kill-region (not bound)
# kill-whole-line (not bound)
"\ed": kill-word
# magic-space (not bound)
# menu-complete (not bound)
"\C-n": next-history
"\eOB": next-history
"\e[B": next-history
"\en": non-incremental-forward-search-history
# non-incremental-forward-search-history-again (not bound)
"\ep": non-incremental-reverse-search-history
# non-incremental-reverse-search-history-again (not bound)
"\C-o": operate-and-get-next
# paste-from-clipboard (not bound)
"\C-x!": possible-command-completions
"\e=": possible-completions
"\e?": possible-completions
"\C-x/": possible-filename-completions
"\C-x@": possible-hostname-completions
"\C-x~": possible-username-completions
"\C-x$": possible-variable-completions
"\C-p": previous-history
"\eOA": previous-history
"\e[A": previous-history
"\C-q": quoted-insert
"\C-v": quoted-insert
"\C-x\C-r": re-read-init-file
# redraw-current-line (not bound)
"\C-r": reverse-search-history
"\e\C-r": revert-line
"\er": revert-line
" ": self-insert
"!": self-insert
"\"": self-insert
"#": self-insert
"$": self-insert
"%": self-insert
"&": self-insert
"'": self-insert
"(": self-insert
")": self-insert
"*": self-insert
"+": self-insert
",": self-insert
"-": self-insert
".": self-insert
"/": self-insert
"0": self-insert
"1": self-insert
"2": self-insert
"3": self-insert
"4": self-insert
"5": self-insert
"6": self-insert
"7": self-insert
"8": self-insert
"9": self-insert
":": self-insert
";": self-insert
"<": self-insert
"=": self-insert
">": self-insert
"?": self-insert
"@": self-insert
"A": self-insert
"B": self-insert
"C": self-insert
"D": self-insert
"E": self-insert
"F": self-insert
"G": self-insert
"H": self-insert
"I": self-insert
"J": self-insert
"K": self-insert
"L": self-insert
"M": self-insert
"N": self-insert
"O": self-insert
"P": self-insert
"Q": self-insert
"R": self-insert
"S": self-insert
"T": self-insert
"U": self-insert
"V": self-insert
"W": self-insert
"X": self-insert
"Y": self-insert
"Z": self-insert
"[": self-insert
"\\": self-insert
"]": self-insert
"^": self-insert
"_": self-insert
"`": self-insert
"a": self-insert
"b": self-insert
"c": self-insert
"d": self-insert
"e": self-insert
"f": self-insert
"g": self-insert
"h": self-insert
"i": self-insert
"j": self-insert
"k": self-insert
"l": self-insert
"m": self-insert
"n": self-insert
"o": self-insert
"p": self-insert
"q": self-insert
"r": self-insert
"s": self-insert
"t": self-insert
"u": self-insert
"v": self-insert
"w": self-insert
"x": self-insert
"y": self-insert
"z": self-insert
"{": self-insert
"|": self-insert
"}": self-insert
"~": self-insert
"\200": self-insert
"\201": self-insert
"\202": self-insert
"\203": self-insert
"\204": self-insert
"\205": self-insert
"\206": self-insert
"\207": self-insert
"\210": self-insert
"\211": self-insert
"\212": self-insert
"\213": self-insert
"\214": self-insert
"\215": self-insert
"\216": self-insert
"\217": self-insert
"\220": self-insert
"\221": self-insert
"\222": self-insert
"\223": self-insert
"\224": self-insert
"\225": self-insert
"\226": self-insert
"\227": self-insert
"\230": self-insert
"\231": self-insert
"\232": self-insert
"\233": self-insert
"\234": self-insert
"\235": self-insert
"\236": self-insert
"\237": self-insert
" ": self-insert
"¡": self-insert
"¢": self-insert
"£": self-insert
"¤": self-insert
"¥": self-insert
"¦": self-insert
"§": self-insert
"¨": self-insert
"©": self-insert
"ª": self-insert
"«": self-insert
"¬": self-insert
"­": self-insert
"®": self-insert
"¯": self-insert
"°": self-insert
"±": self-insert
"²": self-insert
"³": self-insert
"´": self-insert
"µ": self-insert
"¶": self-insert
"·": self-insert
"¸": self-insert
"¹": self-insert
"º": self-insert
"»": self-insert
"¼": self-insert
"½": self-insert
"¾": self-insert
"¿": self-insert
"À": self-insert
"Á": self-insert
"Â": self-insert
"Ã": self-insert
"Ä": self-insert
"Å": self-insert
"Æ": self-insert
"Ç": self-insert
"È": self-insert
"É": self-insert
"Ê": self-insert
"Ë": self-insert
"Ì": self-insert
"Í": self-insert
"Î": self-insert
"Ï": self-insert
"Ð": self-insert
"Ñ": self-insert
"Ò": self-insert
"Ó": self-insert
"Ô": self-insert
"Õ": self-insert
"Ö": self-insert
"×": self-insert
"Ø": self-insert
"Ù": self-insert
"Ú": self-insert
#"Û": self-insert
"Ü": self-insert
"Ý": self-insert
"Þ": self-insert
"ß": self-insert
"à": self-insert
"á": self-insert
"â": self-insert
"ã": self-insert
"ä": self-insert
"å": self-insert
"æ": self-insert
"ç": self-insert
"è": self-insert
"é": self-insert
"ê": self-insert
"ë": self-insert
"ì": self-insert
"í": self-insert
"î": self-insert
"ï": self-insert
"ð": self-insert
"ñ": self-insert
"ò": self-insert
"ó": self-insert
"ô": self-insert
"õ": self-insert
"ö": self-insert
"÷": self-insert
"ø": self-insert
"ù": self-insert
"ú": self-insert
"û": self-insert
"ü": self-insert
"ý": self-insert
"þ": self-insert
"ÿ": self-insert
"\C-@": set-mark
"\e ": set-mark
"\e\C-e": shell-expand-line
"\C-x(": start-kbd-macro
# tab-insert (not bound)
"\e&": tilde-expand
"\C-t": transpose-chars
"\et": transpose-words
# tty-status (not bound)
"\C-x\C-u": undo
"\C-_": undo
# universal-argument (not bound)
"\C-u": unix-line-discard
"\C-w": unix-word-rubout
"\eu": upcase-word
# vi-append-eol (not bound)
# vi-append-mode (not bound)
# vi-arg-digit (not bound)
# vi-bWord (not bound)
# vi-back-to-indent (not bound)
# vi-bracktype (not bound)
# vi-bword (not bound)
# vi-change-case (not bound)
# vi-change-char (not bound)
# vi-change-to (not bound)
# vi-char-search (not bound)
# vi-column (not bound)
# vi-complete (not bound)
# vi-delete (not bound)
# vi-delete-to (not bound)
# vi-eWord (not bound)
# vi-editing-mode (not bound)
# vi-end-word (not bound)
# vi-eof-maybe (not bound)
# vi-eword (not bound)
# vi-fWord (not bound)
# vi-fetch-history (not bound)
# vi-first-print (not bound)
# vi-fword (not bound)
# vi-goto-mark (not bound)
# vi-insert-beg (not bound)
# vi-insertion-mode (not bound)
# vi-match (not bound)
# vi-movement-mode (not bound)
# vi-next-word (not bound)
# vi-overstrike (not bound)
# vi-overstrike-delete (not bound)
# vi-prev-word (not bound)
# vi-put (not bound)
# vi-redo (not bound)
# vi-replace (not bound)
# vi-search (not bound)
# vi-search-again (not bound)
# vi-set-mark (not bound)
# vi-subst (not bound)
# vi-tilde-expand (not bound)
# vi-yank-arg (not bound)
# vi-yank-to (not bound)
"\C-y": yank
"\e.": yank-last-arg
"\e_": yank-last-arg
"\e\C-y": yank-nth-arg
"\ey": yank-pop





Top Visited
Switchboard
Latest
Past week
Past month

NEWS CONTENTS

Old News ;-)

Readline Library

1.3 Readline Init File

Although the Readline library comes with a set of Emacs-like keybindings installed by default, it is possible to use a different set of keybindings. Any user can customize programs that use Readline by putting commands in an inputrc file, conventionally in his home directory. The name of this file is taken from the value of the environment variable INPUTRC. If that variable is unset, the default is `~/.inputrc'.

When a program which uses the Readline library starts up, the init file is read, and the key bindings are set.

In addition, the C-x C-r command re-reads this init file, thus incorporating any changes that you might have made to it.

1.3.1 Readline Init File Syntax Syntax for the commands in the inputrc file.
1.3.2 Conditional Init Constructs Conditional key bindings in the inputrc file.
1.3.3 Sample Init File An example inputrc file.
 
 
From: Philipp Thomas <[email protected]>
Date: Wed, 17 Jul 2002 14:54:00 +0200
Message-ID: <[email protected]>
Subject: Re: [SLE] inputrc config files

Richard Bos <[email protected]> [ Tue, 16 Jul 2002 21:12:58 +0200]:

>if test -z "$INPUTRC" ; then
> INPUTRC=/etc/inputrc
> test -s $HOME/.inputrc && INPUTRC=$HOME/.inputrc
> export INPUTRC
>fi
>
>It looks like the if/test can just be removed from /etc/profile....

If you want this to reach SuSE, you should send it to
[email protected]. Very few SuSE employees read SLE and if they do,
they do it in their free time (or, like me, in their holiday :).

Philipp

/etc/inputrc

Inputrc deals with the mapping of the keyboard for certain situations. This file is the start-up file used by readline - the input related library used by Bash and most other shells.

For more information see info bash -- Node: Readline Init file as well as info readline. There is a lot that can be done with this one rc file.

The following is a base /etc/inputrc along with comments to explain what the various options do.

Please note that comments can not be on the same line as commands in inputrc.

# Begin /etc/inputrc

# Make sure we don't output everything on the 1 line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On 
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the 
# value contained inside the 1st argument to the 
# readline specific functions

"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\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

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# End /etc/inputrc


Global values are set in /etc/inputrc. Personal user values as are set in ~/.inputrc. The ~/.inputrc file will override the global settings file. The previous page sets up Bash to use /etc/inputrc by default. If you want your system to use both, it might be a good idea to place a default .inputrc into the /etc/skel directory for use with new users.

Dies ist meine /etc/inputrc, für Debian oder auch Mandrake. Wahrscheinlich funktioniert sie auf allen modernen Linux-Distros.

Damit reagiert in einer bash die Tab-Taste direkt beim ersten Drücken. Pos1 und Ende sind belegt, BildAuf und BildAb blättern durch die Befehlshistorie.

Viel Spaß damit wünscht

Robert Kehl

# /etc/inputrc - global inputrc for libreadline
# See readline(3readline) and `info rluserman' for more information.

# Be 8 bit clean.
set input-meta on
set output-meta on

# To allow the use of 8bit-characters like the german umlauts, comment out
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.

# set convert-meta off

# try to enable the application keypad when it is called.  Some systems
# need this to enable the arrow keys.
#set enable-keypad on

# see /usr/share/doc/bash/inputrc.arrows for other codes of arrow keys

# do not bell on tab-completion 
# set bell-style none 

# Show all if ambigious.
set show-all-if-ambiguous on
# bash completions does not use more
set page-completions off

# some defaults / modifications for the emacs mode
$if mode=emacs

# allow the use of the Home/End keys
"\e[1~": beginning-of-line
"\e[4~": end-of-line
# those two are for rxvt
#"\e[7~":beginning-of-line
#"\e[8~":end-of-line
# on some xterm
#"\e[H": beginning-of-line
#"\e[F": end-of-line
# on nxterms
#"\e[\C-@": beginning-of-line
#"\e[e": end-of-line

# allow the use of the Delete/Insert keys
# "\e[2~": quoted-insert
"\e[2~": yank                   # Insert
# "\e[3~": delete-char
"\e[3~":delete-char             # Suppr

# mappings for "page up" and "page down" to step to the beginning/end 
# of the history
# "\e[5~": beginning-of-history
# "\e[6~": end-of-history
# alternate mappings for "page up" and "page down" to search the history
"\e[5~": history-search-backward
"\e[6~": history-search-forward

# # mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
#"\e[5C": forward-word
#"\e[5D": backward-word
#"\e\e[C": forward-word
#"\e\e[D": backward-word

# $if term=rxvt
# "\e[8~": end-of-line
# $endif

# for non RH/Debian xterm, can't hurt for RH/DEbian xterm
# "\eOH": beginning-of-line
# "\eOF": end-of-line

# for freebsd console
# "\e[H": beginning-of-line
# "\e[F": end-of-line

$if term=xterm

# xterm with NumLock ON
# Operators
#"\eOo":         "/"
#"\eOj":         "*"
#"\eOm":         "-"
#"\eOk":         "+"
#"\eOl":         "+"
#"\eOM":         accept-line

# Colon and dot
#"\eOl":       ","
"\eOn":         "."

# Numbers
"\eOp":         "0"
"\eOq":         "1"
"\eOr":         "2"
"\eOs":         "3"
"\eOt":         "4"
"\eOu":         "5"
"\eOv":         "6"
"\eOw":         "7"
"\eOx":         "8"
"\eOy":         "9"

# Application keypad and cursor of xterm
"\eOD":         backward-char
"\eOC":         forward-char
"\eOA":         previous-history
"\eOB":         next-history
"\eOE":         re-read-init-file

$endif

$endif

7.8. Creating the -etc-inputrc File

The inputrc file handles keyboard mapping for specific situations. This file is the startup file used by Readline - the input-related library - used by Bash and most other shells.

Most people do not need user-specific keyboard mappings so the command below creates a global /etc/inputrc used by everyone who logs in. If you later decide you need to override the defaults on a per-user basis, you can create a .inputrc file in the user's home directory with the modified mappings.

For more information on how to edit the inputrc file, see info bash under the Readline Init File section. info readline is also a good source of information.

Below is a generic global inputrc along with comments to explain what the various options do. Note that comments cannot be on the same line as commands. Create the file using the following command:

cat > /etc/inputrc << "EOF"
# Begin /etc/inputrc
# Modified by Chris Lynn <[email protected]>

# Allow the command prompt to wrap to the next line
set horizontal-scroll-mode Off

# Enable 8bit input
set meta-flag On
set input-meta On

# Turns off 8th bit stripping
set convert-meta Off

# Keep the 8th bit for display
set output-meta On

# none, visible or audible
set bell-style none

# All of the following map the escape sequence of the
# value contained inside the 1st argument to the
# readline specific functions

"\eOd": backward-word
"\eOc": forward-word

# for linux console
"\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

# for xterm
"\eOH": beginning-of-line
"\eOF": end-of-line

# for Konsole
"\e[H": beginning-of-line
"\e[F": end-of-line

# End /etc/inputrc
EOF

Re bash and inputrc

Re: bash and inputrc


Try doing bash -login, or include a source .inputrc file in the .bashrc 
file.

-        \\||//
---o0O0--Earnie--0O0o----
[email protected]
------ooo0O--O0ooo-------

PS:
The following is from the bash.info file:

`bind'
          bind [-m KEYMAP] [-lpsvPSV] [-q NAME] [-r KEYSEQ]
          bind [-m KEYMAP] -f FILENAME
          bind [-m KEYMAP] KEYSEQ:FUNCTION-NAME

     Display current Readline (*note Command Line Editing::.) key and
     function bindings, or bind a key sequence to a Readline function
     or macro.  The binding syntax accepted is identical to that of
     `.inputrc' (*note Readline Init File::.), but each binding must be
     passed as a separate argument:  e.g.,
     `"\C-x\C-r":re-read-init-file'.  Options, if supplied, have the
     following meanings:

    `-m KEYMAP'
          Use KEYMAP as the keymap to be affected by the subsequent
          bindings.  Acceptable KEYMAP names are `emacs',
          `emacs-standard', `emacs-meta', `emacs-ctlx', `vi',
          `vi-command', and `vi-insert'.  `vi' is equivalent to
          `vi-command'; `emacs' is equivalent to `emacs-standard'.

    `-l'
          List the names of all Readline functions

    `-p'
          Display Readline function names and bindings in such a way
          that they can be re-read

    `-P'
          List current Readline function names and bindings

    `-v'
          Display Readline variable names and values in such a way that
          they can be re-read

    `-V'
          List current Readline variable names and values

    `-s'
          Display Readline key sequences bound to macros and the
          strings they output in such a way that they can be re-read

    `-S'
          Display Readline key sequences bound to macros and the
          strings they output

    `-f FILENAME'
          Read key bindings from FILENAME

    `-q'
          Query about which keys invoke the named FUNCTION

    `-r KEYSEQ'
          Remove any current binding for KEYSEQ

**********************************************************************
Readline Init File
==================

   Although the Readline library comes with a set of `emacs'-like
keybindings installed by default, it is possible that you would like to
use a different set of keybindings.  You can customize programs that
use Readline by putting commands in an "inputrc" file in your home
directory.  The name of this file is taken from the value of the shell
variable `INPUTRC'.  If that variable is unset, the default is
`~/.inputrc'.

   When a program which uses the Readline library starts up, the init
file is read, and the key bindings are set.

   In addition, the `C-x C-r' command re-reads this init file, thus
incorporating any changes that you might have made to it.

* Menu:

* Readline Init File Syntax::   Syntax for the commands in the inputrc 
file.

* Conditional Init Constructs:: Conditional key bindings in the inputrc 
file.

* Sample Init File::            An example inputrc file.

^_
File: bashref.info,  Node: Readline Init File Syntax,  Next: Conditional 
Init Co
nstructs,  Up: Readline Init File

Readline Init File Syntax
-------------------------

   There are only a few basic constructs allowed in the Readline init
file.  Blank lines are ignored.  Lines beginning with a `#' are
comments.  Lines beginning with a `$' indicate conditional constructs
(*note Conditional Init Constructs::.).  Other lines denote variable
settings and key bindings.

Variable Settings
     You can change the state of a few variables in Readline by using
     the `set' command within the init file.  Here is how you would
     specify that you wish to use `vi' line editing commands:

          set editing-mode vi

     Right now, there are only a few variables which can be set; so
     few, in fact, that we just list them here:

    `bell-style'
...

**********************************************************************



>Date: Thu, 27 Nov 1997 10:52:37 +0100
>From: Michael Kalisz <[email protected]>
>To: [email protected]
>Subject: bash and inputrc
>
>My question is simple:
>
>Does the NT bash use the .inputrc or $INPUTRC file?
>
>I added these two lines to my $HOME/.inputrc
>set bell-style none
>set show-all-if-ambiguous on
>
>And I've tried setting the INPUTRC variable but bash
>ignores the settings.
>
>Any suggestions ?
>
>Thanks in advance
>
>Michael
>
>
>
>
>-
>For help on using this list (especially unsubscribing), send a message 
to
>"[email protected]" with one line of text: "help".
>


Linuxart " Blog Archive " Super-useful inputrc

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. (:

20 Responses to "Super-useful inputrc"

  1. Jürg Billeter October 13th, 2005 at 2:08 pm

    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. Marius Gedminas October 13th, 2005 at 3:53 pm

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

    export INPUTRC=~/.inputrc

    to your .bashrc/.bash_profile/wherever.

  3. Colin Marquardt October 13th, 2005 at 5:28 pm

    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

  4. Pádraig Brady October 14th, 2005 at 5:36 am

    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

  5. Wouter October 14th, 2005 at 9:13 am

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

  6. Anonymous October 14th, 2005 at 1:50 pm

    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.

  7. Holy Shmoly! :: Bash Fun - history and navigation October 15th, 2005 at 5:08 pm

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

  8. Francesco January 15th, 2006 at 9:56 am

    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 !!

  9. Jason May 1st, 2006 at 1:15 pm

    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.

  10. Triffid Hunter July 6th, 2006 at 10:36 pm

    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.

  11. micha September 2nd, 2006 at 8:31 pm

    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.

  12. Will February 5th, 2007 at 7:00 pm

    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.

  13. Bryan Harris September 29th, 2007 at 4:26 pm

    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.

.inputrc

# /etc/inputrc - global inputrc for libreadline
# See readline(3 readline) and `info readline' for more information.

# first tab suggests ambiguous variants
set show-all-if-ambiguous on

# bell setup
set bell-style none
set prefer-visible-bell

# show file types while completing
set visible-stats on

# Be 8 bit clean.
set input-meta on
set output-meta on

# To allow the use of 8bit-characters like the german umlauts, comment out
# the line below. However this makes the meta key not work as a meta key,
# which is annoying to those which don't need to type in 8-bit characters.
set convert-meta off

# ask before displaying more than 500 completions
set completion-query-item 500


# Macros that are convenient for shell interaction
# WARNING: Some may be broken
#$if Bash
# edit the path
#"\\C-xp": "PATH=${PATH}\\e\\C-e\\C-a\\ef\\C-f"
# prepare to type a quoted word -- insert open and close double quotes
# and move to just after the open quote
#"\\C-x\\"": "\\"\\"\\C-b"
# Quote the current or previous word
#"\\C-xq": "\\eb\\"\\ef\\""
# Add a binding to refresh the line, which is unbound
#"\\C-xr": redraw-current-line
# Edit variable on current line.
#"\\M-\\C-v": "\\C-a\\C-k$\\C-y\\M-\\C-e\\C-a\\C-y="
#$endif

# Local Variables:
# mode:shell-script
# sh-shell:bash
# mode:outline-minor
# outline-regexp: "#=-.*"
# End:

Recommended Links

Google matched content

Softpanorama Recommended

Top articles

Sites

Top articles

Sites

...



Etc

Society

Groupthink : Two Party System as Polyarchy : Corruption of Regulators : Bureaucracies : Understanding Micromanagers and Control Freaks : Toxic Managers :   Harvard Mafia : Diplomatic Communication : Surviving a Bad Performance Review : Insufficient Retirement Funds as Immanent Problem of Neoliberal Regime : PseudoScience : Who Rules America : Neoliberalism  : The Iron Law of Oligarchy : Libertarian Philosophy

Quotes

War and Peace : Skeptical Finance : John Kenneth Galbraith :Talleyrand : Oscar Wilde : Otto Von Bismarck : Keynes : George Carlin : Skeptics : Propaganda  : SE quotes : Language Design and Programming Quotes : Random IT-related quotesSomerset Maugham : Marcus Aurelius : Kurt Vonnegut : Eric Hoffer : Winston Churchill : Napoleon Bonaparte : Ambrose BierceBernard Shaw : Mark Twain Quotes

Bulletin:

Vol 25, No.12 (December, 2013) Rational Fools vs. Efficient Crooks The efficient markets hypothesis : Political Skeptic Bulletin, 2013 : Unemployment Bulletin, 2010 :  Vol 23, No.10 (October, 2011) An observation about corporate security departments : Slightly Skeptical Euromaydan Chronicles, June 2014 : Greenspan legacy bulletin, 2008 : Vol 25, No.10 (October, 2013) Cryptolocker Trojan (Win32/Crilock.A) : Vol 25, No.08 (August, 2013) Cloud providers as intelligence collection hubs : Financial Humor Bulletin, 2010 : Inequality Bulletin, 2009 : Financial Humor Bulletin, 2008 : Copyleft Problems Bulletin, 2004 : Financial Humor Bulletin, 2011 : Energy Bulletin, 2010 : Malware Protection Bulletin, 2010 : Vol 26, No.1 (January, 2013) Object-Oriented Cult : Political Skeptic Bulletin, 2011 : Vol 23, No.11 (November, 2011) Softpanorama classification of sysadmin horror stories : Vol 25, No.05 (May, 2013) Corporate bullshit as a communication method  : Vol 25, No.06 (June, 2013) A Note on the Relationship of Brooks Law and Conway Law

History:

Fifty glorious years (1950-2000): the triumph of the US computer engineering : Donald Knuth : TAoCP and its Influence of Computer Science : Richard Stallman : Linus Torvalds  : Larry Wall  : John K. Ousterhout : CTSS : Multix OS Unix History : Unix shell history : VI editor : History of pipes concept : Solaris : MS DOSProgramming Languages History : PL/1 : Simula 67 : C : History of GCC developmentScripting Languages : Perl history   : OS History : Mail : DNS : SSH : CPU Instruction Sets : SPARC systems 1987-2006 : Norton Commander : Norton Utilities : Norton Ghost : Frontpage history : Malware Defense History : GNU Screen : OSS early history

Classic books:

The Peter Principle : Parkinson Law : 1984 : The Mythical Man-MonthHow to Solve It by George Polya : The Art of Computer Programming : The Elements of Programming Style : The Unix Hater’s Handbook : The Jargon file : The True Believer : Programming Pearls : The Good Soldier Svejk : The Power Elite

Most popular humor pages:

Manifest of the Softpanorama IT Slacker Society : Ten Commandments of the IT Slackers Society : Computer Humor Collection : BSD Logo Story : The Cuckoo's Egg : IT Slang : C++ Humor : ARE YOU A BBS ADDICT? : The Perl Purity Test : Object oriented programmers of all nations : Financial Humor : Financial Humor Bulletin, 2008 : Financial Humor Bulletin, 2010 : The Most Comprehensive Collection of Editor-related Humor : Programming Language Humor : Goldman Sachs related humor : Greenspan humor : C Humor : Scripting Humor : Real Programmers Humor : Web Humor : GPL-related Humor : OFM Humor : Politically Incorrect Humor : IDS Humor : "Linux Sucks" Humor : Russian Musical Humor : Best Russian Programmer Humor : Microsoft plans to buy Catholic Church : Richard Stallman Related Humor : Admin Humor : Perl-related Humor : Linus Torvalds Related humor : PseudoScience Related Humor : Networking Humor : Shell Humor : Financial Humor Bulletin, 2011 : Financial Humor Bulletin, 2012 : Financial Humor Bulletin, 2013 : Java Humor : Software Engineering Humor : Sun Solaris Related Humor : Education Humor : IBM Humor : Assembler-related Humor : VIM Humor : Computer Viruses Humor : Bright tomorrow is rescheduled to a day after tomorrow : Classic Computer Humor

The Last but not Least Technology is dominated by two types of people: those who understand what they do not manage and those who manage what they do not understand ~Archibald Putt. Ph.D


Copyright © 1996-2021 by Softpanorama Society. www.softpanorama.org was initially created as a service to the (now defunct) UN Sustainable Development Networking Programme (SDNP) without any remuneration. This document is an industrial compilation designed and created exclusively for educational use and is distributed under the Softpanorama Content License. Original materials copyright belong to respective owners. Quotes are made for educational purposes only in compliance with the fair use doctrine.

FAIR USE NOTICE This site contains copyrighted material the use of which has not always been specifically authorized by the copyright owner. We are making such material available to advance understanding of computer science, IT technology, economic, scientific, and social issues. We believe this constitutes a 'fair use' of any such copyrighted material as provided by section 107 of the US Copyright Law according to which such material can be distributed without profit exclusively for research and educational purposes.

This is a Spartan WHYFF (We Help You For Free) site written by people for whom English is not a native language. Grammar and spelling errors should be expected. The site contain some broken links as it develops like a living tree...

You can use PayPal to to buy a cup of coffee for authors of this site

Disclaimer:

The statements, views and opinions presented on this web page are those of the author (or referenced source) and are not endorsed by, nor do they necessarily reflect, the opinions of the Softpanorama society. We do not warrant the correctness of the information provided or its fitness for any purpose. The site uses AdSense so you need to be aware of Google privacy policy. You you do not want to be tracked by Google please disable Javascript for this site. This site is perfectly usable without Javascript.

Last modified: March, 12, 2019