Linux: Make CapsLock Do Home Key

By Xah Lee. Date: . Last updated: .

How to make CapsLock do Home Key on Linux?

Create a file at ~/.Xmodmap with the following content:

! -*- coding: utf-8 -*-
! 2017-02-08
! Linux: Make CapsLock Do Home Key
! http://xahlee.info/linux/linux_capslock_do_home_key.html

! keycode  66 = Caps_Lock NoSymbol Caps_Lock
! keycode 110 = Home NoSymbol Home

clear Lock
keycode 66 = Home NoSymbol Home

Now, run this line in terminal:

xmodmap ~/.Xmodmap

When you restart, that file will run automatically.

Note, xmodmap only works for X11 apps. If you are in linux virtual console [see Linux: How to use Virtual Console] , it won't work.

Here's how to change the key for console.

Change Key for Virtual Console

Written by 11fdriver, on 2018-12-18

Xmodmap does not work when Emacs is used in the console (accessed with Ctrl+Alt+F1 to Ctrl+Alt+F6 ) rather than X11. It's still reasonably simple to change.

Enter the keymap directory (see bottom of `man loadkeys'), and make a copy of your preferred keyboard layout. I use the Dvorak keyboard layout on Void Linux, so my commands are:

$ cd /usr/share/kbd/keymap/i386/dvorak/
# cp dvorak.map.gz xah-fly.map.gz
# Emacs xah-fly.map.gz

Note: Debian and derivatives users may need to install the console-data package:

# apt-get install console-data
$ cd /usr/share/keymaps/i386/dvorak/
# cp dvorak.kmap.gz xah-fly.kmap.gz
# Emacs xah-fly.kmap.gz

The Caps_Lock key is usually bound to keycode 58, and Home to 102, but you should check these yourself using the `showkey' command.

Keymaps often already contain a Caps_Lock binding; just find replace Caps_Lock with Home . The Home key generally needs an extra line to change it to Caps_Lock:

keycode 102 = Caps_Lock !Note: End this file with a blank line.

Test out your new keymap with the `loadkeys' command:

# loadkeys xah-fly.map.gz

On most Linux distributions, load this keymap at boot by editing the relevant line in /etc/rc.conf to read:

KEYMAP=xah-fly

Debian-based distributions instead require you to add this line to /etc/default/keyboard:

KMAP=/usr/share/keymaps/i386/dvorak/xah-fly.kmap.gz

back to Linux: xmodmap Tutorial

Linux Keybinding Howto

Mouse

Linux Desktop keys