This question already has an answer here:

Bash uses GNU Readline. Readline provides a collection of keyboard shortcuts. However, there are some shortcuts that work on bash and that are not documented in Readline reference. Some examples are:

  • C-h - Same as Backspace
  • C-m - Same as Enter (CR I guess)

So why do these shortcuts work? I guess that these may have something to do with ASCII but I am not sure which component provides interpretation of these control sequences as the behavior I have indicated.

Is it the Readline library? Or is it bash itself? Is it my terminal emulator? Is it the kernel? Etc...

What component makes these control sequences behave this way?

Edit: My .inputrc file:

# To the extent possible under law, the author(s) have dedicated all 
# copyright and related and neighboring rights to this software to the 
# public domain worldwide. This software is distributed without any warranty. 
# You should have received a copy of the CC0 Public Domain Dedication along 
# with this software. 
# If not, see <http://creativecommons.org/publicdomain/zero/1.0/>. 

# base-files version 4.2-4

# ~/.inputrc: readline initialization file.

# The latest version as installed by the Cygwin Setup program can
# always be found at /etc/defaults/etc/skel/.inputrc

# Modifying /etc/skel/.inputrc directly will prevent
# setup from updating it.

# The copy in your home directory (~/.inputrc) is yours, please
# feel free to customise it to create a shell
# environment to your liking.  If you feel a change
# would be benifitial to all, please feel free to send
# a patch to the cygwin mailing list.

# the following line is actually
# equivalent to "\C-?": delete-char
"\e[3~": delete-char

# VT
"\e[1~": beginning-of-line
"\e[4~": end-of-line

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

# rxvt and konsole (i.e. the KDE-app...)
"\e[7~": beginning-of-line
"\e[8~": end-of-line

# VT220
"\eOH": beginning-of-line
"\eOF": end-of-line

# Allow 8-bit input/output
#set meta-flag on
#set convert-meta off
#set input-meta on
#set output-meta on
#$if Bash
  # Don't ring bell on completion
  #set bell-style none

  # or, don't beep at me - show me
  #set bell-style visible

  # Filename completion/expansion
  #set completion-ignore-case on
  #set show-all-if-ambiguous on

  # Expand homedir name
  #set expand-tilde on

  # Append "/" to all dirnames
  #set mark-directories on
  #set mark-symlinked-directories on

  # Match all files
  #set match-hidden-files on

  # 'Magic Space'
  # Insert a space character then performs
  # a history expansion in the line
  #Space: magic-space

marked as duplicate by G-Man, Archemar, Jeff Schaller, MelBurslan, jimmij Jun 24 '16 at 18:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


The bindings (whether they appear in the manual or not) appear when you type

bind -p

For instance (partial listing):

"\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)
# backward-byte (not bound)
"\C-b": backward-char
# backward-byte (not bound)
"\C-b": backward-char
"\eOD": backward-char
"\e[D": backward-char
"\C-h": backward-delete-char
"\e[3;5~": 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

The manual documents the -p option:

The bind -p command displays Readline function names and bindings in a format that can put directly into an initialization file. See Bash Builtins.

The bindings (reading the source code) depend on the keymap. The ones I quoted are from the emacs keymap, which is initialized from a built-in table before scripts are applied. There is a corresponding file with tables for the vi keymap.

All of that is part of Readline (which is bundled with bash). When bash starts up, it defines the bindings using these tables. Depending on the other files it reads from /etc/inputrc, ~/.inputrc it may add to, modify or remove some of these built-in bindings.

  • Yes these shortcuts are indeed shown via bind -p. But then, where are these shortcuts defined? They are not in my .inputrc. Are these hardcoded into Readline or are they somehow configurable? – Utku Jun 24 '16 at 6:06
  • sure - they are hardcoded and can be overridden (configurable). – Thomas Dickey Jun 24 '16 at 8:28

As is pointed out in section "1.3 Readline Init File" of the manual you refer to, the readline library is configurable. Keybindings may be defined either in /etc/inputrc, or in your local ~/.inputrc.

  • I am not sure this has to do with .inputrc. I did not observe a place related to these shortcuts in the file. I have posted the file in the question. Do I miss something? – Utku Jun 23 '16 at 13:28

Not the answer you're looking for? Browse other questions tagged or ask your own question.