60

Exactly what the title asks. How do I clear xmodmap settings?

I have an IBM model M, and somehow xkeycaps got it into its head that my End key was not any key at all. xev reports keypresses when I use it, so I know the event is being generated by the keyboard. Also, xkeycaps thinks that my arrow keys are all wonky, and apparently the scrollbar is broken so it only scrolls down - so I can't scroll up to find an IBM keyboard that just maybe is close to my map so I can fix my keys.

So I'm trying to reset my keyboard to the default settings, but the xmodmap manpage is woefully devoid of "reset all" or "clear all" or anything of that nature (that I was able to find).

4 Answers 4

88

xmodmap has no notion of state, so it has no way to reset state directly. You can simulate it by using xmodmap -pke >.xmodmap.orig before making any changes (although it doesn't save the modifier map, which you would have to save and restore manually) — but it's a bit too late for that.

Modern systems don't generally use xmodmap to configure the keyboard, though. setxkbmap is the modern way to do it; and that does reset bindings when run. So you may be able to use setxkbmap -layout us to reset things to normal. More complete would be to check for the default configuration in /etc/X11/xorg.conf. For example, on my system

jinx:718 Z$ sed -n '/Identifier.*Keyboard/,/EndSection/p' /etc/X11/xorg.conf
        Identifier      "Generic Keyboard"
        Driver  "kbd"
        Option  "XkbModel"      "pc105"
        Option  "XkbLayout"     "us"
        Option  "XkbOptions"    "grp:alt_shift_toggle"
EndSection

The corresponding command is

setxkbmap -model pc105 -layout us -option grp:alt_shift_toggle

If there were an XkbVariant entry in the output, you would pass its value with -variant. One thing to watch out for is that options are handled specially: you can only set one option per -option parameter, and you need to use -option '' to reset parameters first. So to fully reset when there is something like XkbOptions "grp:alt_shift_toggle,grp:ctrls_toggle" you would need

setxkbmap -model pc105 -layout us -option '' -option grp:alt_shift_toggle -option grp:ctrls_toggle
4
  • 41
    setxkbmap -layout us has reset my keys, thank you!
    – Dan
    Nov 8, 2011 at 13:20
  • 9
    Another very helpful option I discovered is setxkbmap -query to print out the current settings in xkb's format, which helped me to configure my Apple keyboard as desired from the terminal.
    – metakermit
    Jul 21, 2013 at 11:39
  • 1
    careful with that command of setxkbmap -layout us as it will restore the us layout for every language support you have. For instance my french key layout along with my english key layout turns to be qwerty insteady of azerty..
    – vdegenne
    Apr 2, 2018 at 12:08
  • This question is about xmodmap not xkb. These applications are conflicting, and if your system does use xmodmap (as does modern Ubuntu) you may get confused after using the xkb reset command and then attempt to modify key bindings in xmodmap (as I did) May 15, 2018 at 17:40
37

setxkbmap -option resets the meta keys to default.

5
  • 4
    It worked for me. Jun 8, 2018 at 18:06
  • just what I was looking for, and found on the man page - clears ALL mods.
    – wuxmedia
    Apr 24, 2020 at 8:20
  • This worked for me! I had at some point in time on this machine decided i wanted a regular keyboard to mirror a mac keyboard and swapped Alt and Super. What's driving me nuts is that I have to re-run setxkbmap -option each time i boot now, to undo my horrible idea from before... Some config I added that I need to find is forcing the modifier key swap...
    – Steven Lu
    Aug 28, 2020 at 15:32
  • @StevenLu , check /etc/X11/xorg.conf.d/20-keyboard-layout.conf Dec 21, 2020 at 9:55
  • it's worked kubuntu 22.04 Dec 28, 2022 at 7:17
9

Experimenting with xmodmap, I messed up my key settings by using xmodmap -en "keysym BackSpace = Delete". Thought the -n flag would cause no action to be taken because the man xmodmap page stated that

-n      This  option indicates that xmodmap should not change the mappings, but should display what it would
               do, like make(1) does when given this option.

However, the command caused my Delete key to be useless.

After reading the above, I just typed setxkbmap, hoping it would show me the options, whereas in fact it returned immediately with no output, and then my Delete key was miraculously working again!

So it looks as though

setxkbmap

alone will do the job...

2
  • 1
    simple & perfectly worked! :) Oct 25, 2019 at 13:36
  • 1
    Yeah this is definitely the best solution.
    – Cestarian
    Dec 2, 2020 at 13:14
3

I execute xmodmap commands via terminal.

After restarting GNOME(ALT+f2 r Enter) it reverts back. Kind of workaround but works.

Also this is better option.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .