Keybinding can be done using one of the following forms:
- keyname: command_name
- "keystroke_sequence": command_name
In first form you can spell out the name for a single key. For example, CONTROL-U would be written as control-u. This is useful for binding commands to single keys.
In the second form, you specify a string that describes a sequence of keys that will be bound to the command. The one you gave as an example is the emacs-tyle backslash escape sequences to represent the special keys
\C
- Control
\M
- Meta
\e
- Escape
You can specify a backslash using another backslash – \\
.
Similarly '
and "
can be escaped too - \'
and \"
Update
These characters is what is interpreted by your terminal when you press special keys. You don't want to bind regular alphabets and numerics in your key binding as you might be using them on regular basis and can cause issues when you accidentally hit a combination that has been mapped in your ~/.inputrc
or /etc/inputrc
file.
[1~ is what is interpreted by your terminal when you press your HOME button.
To learn more, simply type read
on your terminal prompt and press all types of special keys like Function Keys, HOME, END, Arrow Keys etc and see what gets displayed.
Here is a small reference I found that can offer some basic understanding. Good luck! :)
Best Answer
TL;DR
To view the default keybindings for (example)
emacs
(the default), use:The
vi
,vi-command
andvi-move
are one and the same keymap.Both
emacs-meta
andemacs-ctlx
are subset views into theemacs
keymap.If you want further info on the
vi
mode and maps, skip to the headingediting-mode vi
(the last one).But wait! There's a fair bit of background info that may be needed though: eg, the difference between an
editing-mode
and akeymap
.Particularly useful is the concept of a hybrid
emacs
keymap for inserting text and while still easily getting tovi-command
for making changes.What is the difference between an
editing-mode
and akeymap
?There are only two
editing-mode
s:emacs
(the default) andvi
.The GNU Readline Library documentation says:
Note the difference between
editing-mode
andkeymap
: Inediting-mode vi
the two (yes there's only two, read on) keymaps are swapped in and out to emulate the different modes of thevi
editor. ALL theemacs
ones operate at the same time inediting-mode emacs
(explained later).So what does
editing-mode
actually do? It just sets the active keymap upon shell startup to eitheremacs
orvi-insert
.What are the unique keymaps?
While not documented,
vi
/vi-command
andvi-move
keymaps are also equivalent:This leaves us with:
emacs
,emacs-meta
,emacs-ctlx
,vi
, andvi-insert
as unique keymaps to explain. Differentiating the keymaps is probably best done by inspecting them...What are the keymaps default bindings?
To view the default keybindings for (example) emacs (the default), use:
You can replace
emacs
with any other keymap name in the example above.There are many lines saying
self-insert
ordo-lowercase-version
which aren't very useful, so to remove them:What is the difference between the various
emacs
keymaps?TL;DR: They are different views on a single set of mappings applied to
editing-mode emacs
.If you the output of the second command into the files called
emacs-standard
,emacs-meta
,emacs-ctlx
,vi-command
, andvi-insert
for their correspondingkeymap
s, you can find out that:There are NO commands mapped in
emacs-meta
andemacs-ctlx
which don't also appear inemacs-standard
:So
emacs
/emacs-standard
is a behaviourally functional superset of bothemacs-ctlx
andemacs-meta
This means that:Is functionally equivalent to:
You might argue that the second form is easier to read.
Inserting text:
emacs
vsvi-insert
There are 28 commands in
emacs-standard
not invi-insert
emacs
/emacs-standard
is basically a superset ofvi-insert
. So for typing text, it's best to use theemacs-standard
keymap overvi-insert
as long as you can easily switch betweenemacs
andvi-command
.The only additional bindings in
vi-insert
not inemacs-standard
are:The first 3 of these four conflict with
emacs
bindings:which I resolved as follows:
editing-mode vi
As we saw above,
vi
,vi-command
andvi-move
are one and the same keymap:Note that's a total of just two distinct maps which are associated by default with
editing-mode vi
.When in
editing-mode vi
, thekeymap
s in use arevi
/vi-command
/vi-move
andvi-insert
(the starting keymap). Only one of these two maps is active at a time.editing-mode vi
does nothing more than set a default keymap when the shell starts, labelledvi-insert
. Again, tthere is only one keymap active at a time. Thisvi-insert
keymap maps most keys toself-insert
so when you press the plastic button on your keyboard, the symbol printed on it appears on your screen.The
vi-insert
keymap allows itself to be swapped to the text-manipulating keymap calledvi-command
/vi
/vi-move
by usingvi-movement-mode
command, bound to the ESC key by default in thevi-insert
keymap.Actually, even the
emacs
keymap can set thevi
-like text manipulation keymap active by using thevi-movement-mode
command, as in the hybrid solution mentioned above.Or in easier language...
By default, press ESC to change to the
vi-command
keymap when thevi-insert
keymap is active.The
vi-command
keymap uses standard, single keypresses like a, b and c to move and interact with text, just like thevi
editor's default or command mode. There are generally no Ctrl+key combinations. You can't insert text in this mode; the letter keys are mapped to editing/moving commands. For typing text, you switch to thevi-insert
keymap (example: press i for "Insert").Entering text is done using the the
vi-insert
keymap, which is active when the shell starts if you haveediting-mode vi
in your.inputrc
file. Swap to thevi-insert
keymap by pressing i for "insert" while invi-command
(or in numerous other ways for those initiated intovi
).Unless you know the
vi
editor, you'll probably findvi-command
keys very hard to use at first, but if you get good at it, you can edit text like a long-bearded wizard.