Oct 01 2007

Vim xkb Poweruser Tip

First, I'd like to say I'm a new vim user. For whatever silly reason, It took me ten years of coding with visual editors to realize, I could be much more productive with a real editor. Boy, do I feel silly for not learning sooner. OK, on with the tip:

First a little background. Many moons ago (1991), Jamie Zawinski had a similar complaint about the keyboard layout as I have. The CAPS LOCK key is very inconveniently located. He created a gui fronted to xmodmap to assist in the modification of the keyboard called XKeyCaps. However, he's since abandoned any further development on this app, feeling that Gnome currently gives enough options for keyboard remapping. Also, with Xorg, xkb has transplanted the functionality of xmodmap, so all the tips and tricks that permeate the internet on the subject are not addressing the fact that the system is really using xkb. Now, while I agree that Gnome has given quite a few options provided by the xkb layouts, there is one change it doesn't have: switching the caps lock and esc keys. Jamie likes to switch the Caps Lock and Ctrl keys, I have a slightly different opinion on the matter.

Why would I want to switch these keys? First and foremost, if you accidentally hit the caps lock while using vim, many, many bizarre things start to happen, as it recognizes these as very different commands from what you expect. (Thankfully there is a large undo buffer). Secondly, it is utilizing prime real estate on the keyboard and is rarely used. The following is my quick and dirty for changing the default behavior of switching the left ctrl key and the caps lock key (because I can't for the life of me see how this would be useful).

Step 1.

As root, edit the following file:

# vi /usr/share/X11/xkb/symbols/ctrl
$ sudo vi /usr/share/X11/xkb/symbols/ctrl

Find the following line:

xkb_symbols "swapcaps" {

To make the switch, this section should read:

xkb_symbols "swapcaps" {
key <CAPS> { symbols[Group1]= [ Escape ] };
key <ESC> { symbols[Group1]= [ Caps_Lock ] };

After restarting X (CTRL+ALT+BACKSPACE). In Gnome, on your main menu select System -> Preferences -> Keyboard :: Layout Options Tab. Toggle Ctrl key position arrow and select "Swap Ctrl and CapsLock". This of course now will switch the CapsLock and ESC keys.

I'm sure there are better ways to change the behavior of XKB. If you know of any better way, please email me or comment here. Root file modifications suck. I should be able to quickly and easily change this in my gui. I loathe having "built-in" options. They never take into account all personal preferences. Also if any Xorg or Gnome devs read this, if xmodmap is deprecated, please, for the sake of users sanity, deprecate the damn thing and allow users to change keyboard mappings.

Only drawback of this is that the next time you update Xorg, all your changes will be lost. However, as much as they've been mucking around with changes lately, that would likely be the case for any user space changes as well.

Remember to backup any files you modify.


free b2evolution skin
Too Cool for Internet Explorer