After I had a new monitor in the workplace, I began a new iteration of improving my “mouseless” (
mouse-less, approx. ) Experience. You know what that means, don't you? This means that every time you take up the mouse, removing your hand from the keyboard, you spend a little time and energy. If you need to type a lot of text (and I write a lot of code), this becomes significant.
There is also the next level of “thoughtless” experience, when you try to avoid hard-to-reach keys, for example,
Delete
,
Backspace
,
Escape
or even
Enter
.
If you hold your hands in a standard position for 10-finger blind typing, it is more convenient to press
Ctrl-m
instead of reaching with your little finger to enter.
')

In this article I will talk about convenient keyboard shortcuts that can be used in any terminal, although they work in many other places.
For a start, a comparative table:
Title | Typical key | Convenient alternative |
---|
Start line | Home | Ctrl-a |
End of line | End | Ctrl-e |
One character forward | Right Arrow | Ctrl-f |
One character back | Left Arrow | Ctrl-b |
Delete the character under the cursor | Delete | Ctrl-d |
Delete the character in front of the cursor | Backspace | Ctrl-h |
Previous team in history | Up Arrow | Ctrl-p |
Next team in history | Down Arrow | Ctrl-n |
Enter command | Enter | Ctrl-j or Ctrl-m |
As a bonus, here is another list of convenient combinations:
Title | Keyboard shortcut |
---|
Cut the previous word | Ctrl-w |
Cut all to end of line | Ctrl-k |
Cut all to the beginning of the line | Ctrl-u |
Paste previously cut | Ctrl-y |
Undo the change | Ctrl-_ (Ctrl+Shift+-) |
Clear screen | Ctrl-l |
Do not forget to try these combinations in other applications. I think you will be surprised how widely they are supported.
Why does it work
First of all, there is a widely used
readline
library. Try to remove it from your system, and you will find out how many applications depend on it (
THIS WAS A BAD JOKE. DO NOT DO THIS ). From the official
home page :
The GNU Readline library provides a set of functions that allow the user to edit input commands right at the input location.
This means that the application can simply use this library for user input, and it will take care of all the "buns". From the
official documentation, you can find out that it supports
emacs and
vi modes, where the first one goes by default. Vi mode is more familiar to the Wimmers, however there is one major drawback: there is no indicator of the current mode.
readline
provides most of the combinations, but not all. Among them are
Ctrl-h
,
Ctrl-m
,
Ctrl-j
. But why do they work? I think you will like the answer.
Do you remember the
ASCII character table? There at the beginning of the table there are 32 old unnecessary control characters. And if you look at the
Ctrl-m
combination with the
xev
utility, you will see
<code> KeyRelease event, serial 34, synthetic NO, window 0x1800001,
root 0x103, subw 0x0, time 17907461, (780,924), root: (3342,946),
state 0x4, keycode 58 (keysym 0x6d, m), same_screen YES,
"XLookupString gives 1 bytes: (0d)"
XFilterEvent returns: False
</ code>
that
XLookupString
returns
0x0d bytes for this combination. A
0x0d byte is nothing more than a
carriage return control character, also known as
\r
. This control character tells the terminal to accept your command, working in the same way as
Enter
. So, control characters are not so unnecessary (well, at least some of them).
Another interesting question is how does the system determine the relationship between the
Ctrl-m
combination and the carriage return symbol. The answer to this is no less interesting -
Caret notation : a method of writing control characters using printed characters. The rule is very simple: just inject the seventh bit in the code of the control character, and get the corresponding printed one. On the one hand, everything is simple; on the other hand, it is impossible to reassign. But don't believe me, check it out
here .
That's all. I hope the material was helpful. Improve!
PS The mode indicator in the
readline
is still present, starting with version 6.3. To do this, add
set show-mode-in-prompt On
to ~ / .inputrc. Thank you
xaizekPSS The ascii code table can be viewed with the
man ascii
command. Again, thanks
xaizek