How do I remap the caps lock key?

68,252

Solution 1

From howtogeek.com which has a good answer for any OS.

For Linux (including Ubuntu):

setxkbmap -option <OPTION>

Where <OPTION> can be for example of:

  • caps:none – Disables Caps Lock.
  • caps:super – Caps Lock becomes an additional Super (aka Win key).
  • caps:ctrl_modifier – Caps Lock becomes an additional Ctrl.
  • caps:numlock – Caps Lock becomes an additional Num Lock.
  • caps:escape – Caps Lock becomes an additional Escape.
  • caps:backspace – Caps Lock becomes an additional Backspace.
  • caps:swapescape – Caps Lock becomes Escape, and Escape becomes Caps Lock

Note: Xmodmap is deprecated in favor of setxkbmap.

Solution 2

In Ubuntu 11.10 - 13.04

  1. Open the Keyboard Layout application and click the "Options" button.
  2. A list of rebinding options will apear. Select "Caps Lock key behavior".
  3. Select your preferred Caps Lock repurposing option.

Screenshot of available options

Solution 3

You can disable it by going to keyboard->Layouts->options->caps lock behavior and choose "disable caps lock" .


Edit:

I don't know why it seems inconvenient with another Keyboard keys.

But Launchy works fine with me after trying it with CTRL+Super+Space.

enter image description here

And you need to white-list launchy to the tray icons. See How do I access and enable more icons to be in the system tray?. Also you need to add it to the Start Up applications, as it won't work when it is not opened.


After all, As an alternative for Launcy, try Synapse for its best integration with gnome and unity.

Solution 4

This is basically a modification of the answer provided at https://askubuntu.com/a/223674/22073.

You can also modify the behavior of Caps Lock using an XKBOption. These changes are even propogated to the virtual consoles (/dev/tty[1-6], or Ctrl-Alt-F[1-6]).

For instance, to disable Caps Lock, you would have the following in /etc/default/keyboard:

# Check /usr/share/doc/keyboard-configuration/README.Debian for
# documentation on what to do after having modified this file.

# The following variables describe your keyboard and can have the same
# values as the XkbModel, XkbLayout, XkbVariant and XkbOptions options
# in /etc/X11/xorg.conf.

XKBMODEL="pc105"
XKBLAYOUT="us"
XKBVARIANT=""
XKBOPTIONS="caps:none"

# If you don't want to use the XKB layout on the console, you can
# specify an alternative keymap.  Make sure it will be accessible
# before /usr is mounted.
# KMAP=/etc/console-setup/defkeymap.kmap.gz

Then you would run:

sudo dpkg-reconfigure keyboard-configuration

For a full list of the customizations of XKBOPTIONS, take a look at /usr/share/X11/xkb/rules/base.lst. Here's the full list from my Ubuntu 13.10 machine: http://sprunge.us/cUZO

Even more information can be found on the ArchLinux wiki: https://wiki.archlinux.org/index.php/Keyboard_Configuration_in_Xorg

Solution 5

To remap the useless caps_lock into a basic shift, do

xmodmap -e "keycode 66 = Shift_L"
Share:
68,252

Related videos on Youtube

user541686
Author by

user541686

Updated on September 18, 2022

Comments

  • user541686
    user541686 almost 2 years

    In the the past I used to use xmodmap to prevent the Caps Lock button from working, and then tell Launchy to handle the key press instead. I can't seem to do this anymore.

    What is the best way to disable Caps Lock's normal behavior, and make it do something else?

  • Jjed
    Jjed over 11 years
    @JacobJohanEdwards Note to self, check whether xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape' still works.
  • rpattabi
    rpattabi over 11 years
    For vim users, 'Practical Vim' recommends to map the caps lock to ctrl at the system level. Keyboard Layout > Options > Ctrl Key Position > Caps Lock as Ctrl does the trick.
  • Czarek Tomczak
    Czarek Tomczak over 10 years
    This does not persist after restart.
  • Czarek Tomczak
    Czarek Tomczak over 10 years
    To make it persist after restart do: Ubuntu Dash Home > Startup Applications > Add > Type the command above.
  • pcworld
    pcworld over 10 years
    These settings don't exist anymore in 13.10. Install gnome-tweak-tool, there you will have similar settings under "Typing".
  • Vitaly Zdanevich
    Vitaly Zdanevich about 10 years
    After few minutes settings go back - and again Caps Lock have usual behaviour.
  • Andrew Wagner
    Andrew Wagner about 10 years
    This is not working for me in Ubuntu 12.10. Messing with those settings in the gnome-control center don't seem to have any effect.
  • nysse
    nysse over 9 years
    This does not help with a laptop.
  • MichielB
    MichielB over 8 years
    This option does not seem to be available to me on Ubuntu 15.04.
  • Andrzej Rehmann
    Andrzej Rehmann over 8 years
    love you man, thanks , it works for ubutnu 14.10
  • Léo Léopold Hertz 준영
    Léo Léopold Hertz 준영 over 8 years
    Why did they remove these options from 14.04?
  • chepyle
    chepyle about 8 years
    nice and simple, works in 16.04
  • landroni
    landroni almost 8 years
    To restore any setxkbmap changes (i.e. if you need your Caps key back to its original location) one only needs to run this: setxkbmap -option
  • Gabriel
    Gabriel over 7 years
    If you remaped the Capslock key to backspace and now you wonder why it won't delete words if you keep it pressed, it's because you need to use an extra command. After setxkbmap -option caps:backspace enter xset r 66 and voilá.
  • Pouya Sanooei
    Pouya Sanooei about 7 years
    what if I want to remap right alt to escape? alt:escape doesn't work
  • Márcio
    Márcio almost 7 years
    Perfect, I'm using XKBOPTIONS="ctrl:swapcaps" to swap the Left Ctrl with Caps.
  • jfs
    jfs almost 7 years
    It works on 16.04 in X and the virtual consoles.
  • Alex Reinking
    Alex Reinking about 5 years
    how would I remap caps to the spacebar?
  • artu-hnrq
    artu-hnrq over 4 years
    It also works at 18.04 LTS Bionic Beaver! Nice solution
  • George Mogilevsky
    George Mogilevsky over 4 years
    this is the best answer i've seen! oh and did i mention that it works?! upvote!
  • Waldir Leoncio
    Waldir Leoncio almost 4 years
    To see a list of available options, try less /usr/share/X11/xkb/rules/base.lst (Ubuntu 18.04; the location of base.lst might change on your system).
  • Adalbert Hanßen
    Adalbert Hanßen over 3 years
    I have installed an autostart script which disables Caps Lock. However after returning from a suspend (=sleep) state, the Caps Lock key becomes operational again (at least in Xubuntu 18.04). Any Idea how to also plug this script into waking up after returning from the sleep state?
  • Mikko Rantalainen
    Mikko Rantalainen about 3 years
    I would suggest doing xmodmap -e "keycode 66 = Shift_L Caps_Lock" instead so that you can still access the normal caps lock using key combination Shift+Caps lock if needed. For other purposes, the caps lock key behaves as additional left shift.