I cannot make xmodmap run on login in Ubuntu 13.04. I have searched around, including in askubuntu and all answers I found do not work.
I have a file named .Xmodmap in my home folder which contains the desired mappings. If I run it manually it works fine, so there is no error there. In order to make it run on startup, I have tried:
Using various
.xinitrc
containing one of the following commands:xmodmap .Xmodmap
xmodmap ~/.Xmodmap
/usr/bin/xmodmap /home/NAME/.Xmodmap
if [ -s ~/.Xmodmap ]; then
xmodmap ~/.Xmodmap
fi
Using
.Xresources
instead of.xinitrc
with the same variations.Setting it as a startup application.
None of the above works in Ubuntu 13.04 (64-bit). I also saw a few ideas about globally changing the keyboard mappings, but most of them were not applicable in Ubuntu 13.04 (i.e. the corresponding files did not exist where specified) and I prefer not to touch the global settings anyway.
Ubuntu no longer uses
xmodmap
, but instead usesxkb
(as far as I understand, this facilitates per-window keyboard layouts, among other things).The system-wide map files are in
The maps appears to be loaded hierarchically, with the
pc
map as the root, and whatever language (e.g.en
) as a child of the root.In my particular case, I physically swapped Page Up with Home and Page Down with End on my keyboard, so I very crudely made changes to the system-wide
pc
map, as follows:NOTE: To force Xorg to use your new keyboard map, you may have to remove the existing pre-compiled maps (*.xkm) in
and then restart Xorg.
There are various resources on
xkb
, but this one is related to Ubuntu.For me, the xkb configuration is too complicated if you want to remap 1 or 2 keys in a way not available in the System Settings. Plus, the solution should remain on the user side, without editing '/usr/share/X11/xkb/symbols/' etc. Force the 'xmodmap ~/.Xmodmap' load using the Startup Applications only works until you suspend, change users or change the keyboard layout. So, as holocronweaver suggests, with code snippets I found, I made a python script to be loaded on session startup, that reloads the '~/.Xmodmap' when needed.
Check the bug report #1243642 (comment #6), and download it here.
I had this problem in Ubuntu 14.04, and found the solution here. Apparently, Ubuntu is not able to configure the keyboard right away after logging in, but it is a bit later. So if you add a command
to
~/.bash_profile
then it should work (it does for me).EDIT: This seems to work only after logging in, not after starting up. I'll have to investigate this later.
Convert Caps Lock into Esc for
vim
useHere is my variant of a key mapping startup script. It converts Caps Lock into Esc on whatever keyboard for use with
vi
,vim
orgvim
.Unlike the answer of q4w56, this answer does not use any infinite
while; do
loop. Otherwise, one core of my dual core CPU would hit 42% every 5 seconds, severely reducing my laptop battery charge.Save it as a script. Make the file executable with
chmod +x
. Add the script name and location toSession and Startup → Application Autostart
(in Xubuntu).The keyboard behaviour for this user will remain persistent through reboot and logout, but not suspend. Persistence through suspend can be achieved, but unfortunately only at the system level, not readily at the user level.
EDIT
I moved away from above solution in favour of this solution which offers, apart from the Esc function on CapsLock, also the arrow keys ←↓↑→ and the keys PgUpHomeEndPgDn through CapsLock+HJKL, respectively CapsLock+UIOP.
Rationale for this keyboard remapping
In today's computing world there is very little use left for the Caps Lock key. In general, one should refrain from using ALL CAPS by virtue of both netiquette and the separation of presentation and content. Moreover, accidentally hitting the Caps Lock key whilst editing text with
vim
is not always immediately noted, but invariably results in rather annoyingvim
behaviour further on. Disabling the Caps Lock key all together and repurposing it as an easy to reach Esc key results in a double win forvim
use.@Daniel's answer pointed me the right way, but I would like to extend on it.
Works for me on Linux Mint 17.2 and Ubuntu 16.04.
I tried all twists I could think of to keep using
xmodmap
, but they all fail when the system goes into sleep mode. The same even holds for start up-applicication scripts that usesetxkbmap
in cases where the *settings-daemon (for me it is xfce4) runs later than the script --- and order cannot really be influenced.What I finally came up with has the following ingredients:
1) Write a minimal keyboard mapping file for
/usr/share/X11/xkb/symbols
. Lets call the filemylayout
It can be as simple asbasic
is just a name, we'll meet it later again.name[Group1]
similarly is just a name it seems, but it will play no role later.include "us"
includes the plain us keyboard. Actuallyus
is another file in the same directory. This is the keyboard layout we are adapting. Choose a different one as needed. Note: no semicolon to end this line.key
line is one adaptation of the keyboard, more can follow. The<AE03>
can be found in the files under/usr/share/X11/xkb/keycodes
. Use thexev
program to figure out that the "3"-key has keycode 12 and in the keycodes fileXfree86
it is mapped to<AE03>
.include
directive to activate another keyboard option, in this case I want to have the right Alt-key to be the level-3 shift key, i.e. the key which gives access to thesterling
sign I defined above.level3
is just a file name in the same folder withralt_switch
one section of it. Have a look around and choose what you need to include.2) I did not put the
mylayout
into the system folder. Rather I made only a soft link from the system folder to a folder of my liking to immediately see that this is not stock software.3) Further I did not fix up
evdev.xml
, again to prevent update hassles. But this would be necessary to find mylayout in the keyboard configuration editor (for xfce4 it isxfce4-keyboard-settings
). Instead I usedxfce4-settings-editor
and changedkeyboard-layout->XkbLayout
tomylayout
(the file name) andXkbVariant
tobasic
(see above). Afterwards,mylayout/basic
is displayed in the keyboard settings editor too. An entry inevdev.xml
seems to be only necessary to be able to select the layout.This way, the keyboard settings now survive sleep mode and reboot.
More background can be found here: http://www.charvolant.org/~doug/xkb/html/node5.html .
Another approach to fixing the sleep mode problem (not tried myself), can be found here: https://www.vinc17.net/unix/xkb.en.html .
UPDATE: worked with Mint 18.3 the same moment I changed the settings in xfce4-settings-editor as described above.
UPDATE: With 18.04, gdm3 as the display manager and XFCE4 as the window manager, it looks as if ~/.Xmodmap is read again and the settings seem to survive a suspend. (I rarely use suspend and I am never sure which mode the laptop is in then really.)
I had the problem too on Ubuntu 16.04 with fcitx, and had the solution on the fcitx wiki, but it need fcitx has 4.2.7 or later
touch ~/.Xmodmap
There also have some explanation for the reason.
REVISION
An update in early 2018 broke persistence -- auto-reload of the keymap after suspend or hibernate. Since methods using /etc/pm/sleep.d scripts stopped working (deprecated?), that left only the newer way, using /lib/systemd/system-sleep and slightly different scripting (which started working on keymaps!).
So this post is updated to the newer method for persistence, and to include normal initial keymap loading, which also started working. The routine for converting an .Xmodmap file to .xkbmap remains unchanged.
Note this is a per-user solution. For a per-device answer, see how to apply a keymap to a single device. This method could be adapted for use here.
First modify the .Xmodmap file as desired. These are easier to edit directly than .xkbmap files. When it is loaded:
then convert to an .xkb file:
To auto-load on startup, open Startup Applications, click Add, and on the Command line enter:
("user" is replaced with actual user name.) For Name, perhaps enter Load Keyboard Map. Add comment if desired and hit Save.
The keymap will now load every time the system boots, but will not survive a suspend or hibernate. For this, create a new file in /lib/systemd/system-sleep, perhaps named 60_xkbmap, which contains:
(Ref.) As above, replace "user" with actual user name.
The keymap should now auto-load and remain persistent. Note:
Steps mentioned in the accepted answer(also described here) is a persistent solution, but didn't work for me in case of altering alphabetical keys.
If you got frustrated by trying other options or want to save your time, try the steps mentioned in the article - https://medium.com/@saplos123456/persistent-keyboard-mapping-on-ubuntu-using-xmodmap-cd01ad828fcd
xmodmap
.This made me stumble, too, when I upgraded from Ubuntu 12.04 to 13.04.
Luckily this setting is now (or perhaps has always been) easily accessible in the Keyboard preferences and can be changed with a few clicks of the mouse.
There you go: Left Control and Caps Lock have switched positions.
Don't forget to delete
~/.Xmodmap
once you've made the change.I find adding this script to startup satisfying:
I tried using
xmodmap ./Xmodmap
, but every time it is executed, a noticeable lag will occur.