I'm using "standard" just in case there's some obvious method, or this feature is part a larger issue that I'm not aware of (as in perhaps involving enabling related shortcuts and features). Otherwise I don't mind just adding my own shortcuts.
-
1On what operating system? FreeBSD? TrueOS? OpenBSD? NetBSD? Illumos? A Linux operating system? ... – JdeBP Jan 03 '17 at 08:57
-
I just updated the tags. – argle Jan 03 '17 at 09:16
2 Answers
If your shell uses the readline
library, here is what I have in my default /etc/inputrc
file:
# mappings for Ctrl-left-arrow and Ctrl-right-arrow for word moving
"\e[1;5C": forward-word
"\e[1;5D": backward-word
"\e[5C": forward-word
"\e[5D": backward-word
"\e\e[C": forward-word
"\e\e[D": backward-word
This file is only read if the INPUTRC
environment variable is not set, and if you don't have any .inputrc
file in your home directory.
Now, we must instruct the console to emit one of the backward-word
strings when Ctrl-Left is pressed, and one of the forward-word
strings when Ctrl-Right is pressed.
For this, we must add some special keyboard mappings to /etc/console-setup/remap.inc
:
# Ctrl + Left arrows key (readline's backward-word)
control keycode 105 = F200
string F200 = "\033[5D"
Ctrl + Right arrows key (readline's forward-word)
control keycode 106 = F201
string F201 = "\033[5C"
Here I have borrowed two keysyms F200
and F201
(picked up quasi randomly from the output of dumpkeys --long-info
) in order to store the sequences expected by readline
. keycode 105
is the left arrow, and keycode 106
is the right arrow (those keycodes were obtained with dumpkeys
too).
Now, let's rebuild our new keymap :
setupcon --save-only
It should (re)create the file /etc/console-setup/cached.kmap.gz
. You can load it manually with the command:
loadkeys /etc/console-setup/cached_UTF-8_del.kmap.gz
Or, better, similarly to when your machine boots:
service console-setup start
UPDATE 2023
Current Debian releases use /etc/console-setup/cached_UTF-8_del.kmap.gz
instead of /etc/console-setup/cached.kmap.gz
.

- 2,417

- 17,793
- 2
- 53
- 69
-
You have them (so do I), but do they work? In the non-GUI console? (That would be amazing.) – argle Jan 03 '17 at 10:21
-
-
@MrShunz Just test them in the *kernel* console and you'll understand what I mean. – argle Jan 09 '17 at 06:57
-
@argle What i meant is that you asked if they work, as if you haven't tried them yourself. That said, I don't have a debian machine at hand, but on my ubuntu system they don't work on tty console (same
/etc/inputrc
though). – Daniele Santi Jan 09 '17 at 09:40 -
@MrShunz No, I haven't tried it myself (obviously). It's xhienne's machine and only he can try; that's why I needed to ask him :P. I could (and did) only try it on my machine (obviously; hence my SE question and note that I said I'd already had those very same configuration lines) and I found it amazing that (xhienne implied) it worked on his machine. By the way, try it on your *non*-Debian machine and you'll see that it's not working either. – argle Jan 10 '17 at 09:28
-
-
Sorry @angle for my silence. You are right that my solution is not sufficient, I missed the fact that it is working for you except on the console. Indeed, it's not working for me either. My understanding, base on
dumpkeys
output, is that there is no character sequence defined for Ctrl+arrow. I'll try and come back with a solution shortly. Ping me if this is not the case, or if you have found the solution yourself. – xhienne Jan 10 '17 at 10:29 -
@argle I have updated my answer with a solution that I have tested on my machine (I did not test the reboot though). – xhienne Jan 10 '17 at 13:30
-
@xhienne Not working, unfortunately. The remap.inc additions seem to be fully ignored (the commands run fine; no error messages). By the way, the /etc/inputrc method does work, it's just that the console takes the
\e
literally (as the escape key, not as the control key). If I press escape and then the arrow key once in the console, the cursor moves one word away. I tried with \C instead of \e and control still won't do anything. – argle Jan 11 '17 at 08:08 -
@argle The ESC+arrow behaviour is normal. With readline, ESC is the
meta
key (see readline's manpage). I suspect the new keymap is not loaded. I have updated my answer to include a manual loading. Can you check 1. that thecached.kmap.gz
file is indeed recreated, 2. that it contains the content ofremap.inc
, and 3. that theloadkeys
command succeeds? – xhienne Jan 11 '17 at 12:57 -
It WORKS! It wasn't the manual loading that made the difference. It seems the original
/etc/console-setup/cached.kmap.gz
needs to be removed before usingsetupcon --save-only
. I didn't understand your solution, by the way. How did you come up with theF200
andF201
? – argle Jan 11 '17 at 23:17 -
@argle It's really weird that
setupcon
didn't succeed in overwriting the previous cache (I assume you are root). As for F200 and F201, those are (hopefully) empty slots, I just had to choose two keysyms fromdumpkeys -l
output. I could have used F77 and F29. I just used high enough numbers to avoid collisions with possible existing definitions on your side. – xhienne Jan 11 '17 at 23:27 -
Yes, root. Otherwise I get
/etc/console-setup is not writable. No files will be saved there.
anyway. – argle Jan 11 '17 at 23:36 -
1Thanks for this useful answer @xhienne. A few more infos for further readers: The key code for left/right might be 113/114 on some systems. Only some OS-es seem to be off by 8. You can show keycodes with
xev
, find possible keysyms withsudo dumpkeys -l
and keycodes in use withxmodmap -pke
and print input codes emacs style (inputrc) withctrl+v keypress
. – phil294 Apr 13 '21 at 21:50
For Linux console, you can customize your keymap. The place to start is with dumpkeys
. That's the standard approach. There's no applicable standard for Linux console bindings, but you can certainly imitate GUI (i.e., xterm as hinted by xhienne).
I don't see a duplicate, but these would be helpful:

- 76,765
-
+1 for the help. I'll test it as soon as I get some time and I'll return with updates. – argle Jan 03 '17 at 22:52
-
I did some more reading. It turns out I understood your solution; it was just unrelated to my question. I hope I'll make inputrc work and post the answer here soon. – argle Jan 09 '17 at 06:55