39

The following happens on different Linuces:

When I'm in a virtual console, hold Alt and press or , the virtual ttys cycle. This is really annoying as I'm using fish-shell which also uses this key combo. I could remap fish's short cuts, but I don't want to. Instead I want to disable the linux function or remap it.

How can I disable or change the tty-cycling-key-combo?

1

5 Answers 5

48

Here's a one-off fix:

sudo sh -c 'dumpkeys |grep -v cr_Console |loadkeys'
1
  • I would suggest adding this as a command in 'startup applications'. Sep 12, 2019 at 16:24
22

I refactored Tobu's answer to change only the absolutely necessary:

sudo sh -c 'dumpkeys -k|grep -v Incr_Console|grep -v Decr_Console|grep -v Last_Console|loadkeys'

NB: As said this is a one-off fix, and will probably be gone after a reboot.

3
  • 1
    Two fixes: 1. Dump only key bindings, to avoid a syntax error in loadkeys; 2. Also get rid of Last_Console (Alt+Tab): sudo sh -c 'dumpkeys|grep -v Incr_Console|grep -v Decr_Console|loadkeys' Thanks very much for this! Apr 4, 2017 at 21:20
  • Further to my previous comment, I discovered that the Caps Lock light was still going on and off (even though Caps Lock was still mapped to Control on my system). To fix this, filtering out the line containing Caps_Lock does not work, as it's the only mapping for the relevant keycode, so is not overwritten when the filtered list of mappings is reloaded. In the end, the simplest solution was to dump a "known good" keymap, and then explicitly load that. Apr 5, 2017 at 9:16
  • Thank you SO much, Tobu & Gunar. I was getting crazy for MONTHS by NOT knowing what was happening. I first thought it was an IDE problem, given I was noting a full redraw, then when I bought my monitor to use it as second screen I noted BOTH screens flicker! And then I suspected I was something to do with X and shortcuts being assigned or something. And THEN YOU come with those AWESOME solutions!!! THANKS SO MUCH. I'm now trying to put that into a autostart script. Feb 4, 2021 at 6:46
16

I had the problem sometimes with Ubuntu 18.04:

sudo kbd_mode -s

Did the job. (at least temporarily)

You can find a long bug report here on launchpad .

5
  • How does this work? I am hesitant to experiment because the man page says "Warning: changing the keyboard mode, other than between ASCII and Unicode, will probably make your keyboard unusable."
    – nshiff
    Sep 9, 2018 at 15:57
  • 1
    Hi, I have added a link.
    – COil
    Sep 9, 2018 at 16:32
  • Thanks! This worked. I tried to click "Yes, it affects me" at bugs.launchpad.net/ubuntu/+source/console-setup/+bug/520546 but I keeping getting a timeout error. Any idea how to fix that?
    – 6005
    Apr 21, 2019 at 17:41
  • It should be temporarily I suppose or you must full a bug report for the bug reporting system itself! :p
    – COil
    Apr 23, 2019 at 9:53
  • worked for me, thanks :)
    – cosurgi
    May 18, 2021 at 17:46
14

You can use the loadkeys command to remap keys on the Linux console. The following lines define the key bindings to switch consoles (on a PC keyboard):

alt keycode 105 = Decr_Console
alt keycode 106 = Incr_Console

Load your own keymap file that overrides these bindings with an escape sequence that fish recognizes. To make a key send an escape sequence, you need to bind it to a key name of the form FNUMBER and define a character sequence for FNUMBER.

alt keycode 105 = F105
alt keycode 106 = F106
string F105 = "\033\033[D"
string F105 = "\033\033[C"

Different distributions (and sometimes different packages for console support) store the system boot-time keymap in different locations under /etc. Look for a file called *.kmap or *.kmap.gz or *.map or *.map.gz under /etc or consult your distribution's manual. Some distributions store a the keymap's name in /etc instead and put the actual keymap elsewhere; look for a keymap-related setting under /etc/sysconfig or other configuration directory.

You can either write your own keymap and use include "/path/to/foo.map" to reference the system keymap, or arrange to load your own keymap containing just the settings you want to change during the boot process.

6
  • Are you sure about the .kmap extension? I wasn't able to find any files on Fedora 20, but on the other hand I found /lib/kbd/keymaps/legacy/i386/qwerty/us.map.gz. Jul 24, 2014 at 0:38
  • @CristianCiupitu My bad, I should have mentioned other ways this can be done. I think that on Fedora there's a setting somewhere in /etc/sysconfig that determines the name of the keymap file to load on startup. Jul 24, 2014 at 0:46
  • Should I get my setup with dumpkeys, save it, change it and change it in /etc/sysconfig? Will that make it persistent?
    – bot47
    Jul 24, 2014 at 1:41
  • @Gilles, perhaps the man pages for systemd-vconsole-setup.service and [vconsole.conf ](freedesktop.org/software/systemd/man/vconsole.conf.html) can shed some light on this. Jul 24, 2014 at 2:46
  • @MaxRied I recommend keeping the two separate, it'll be easier to maintain. Change the reference in /etc/sysconfig to a file that contains an include directive to the standard keymap. Jul 24, 2014 at 7:38
0

On my modern systemd system, I ran localectl set-keymap us and localectl set-x11-keymap us, which resolved this issue for me.

In general, the simplest way of setting keymaps on systemd systems is probably localectl. See the Arch Wiki for further details.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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