VIM Key Bindings In Ubuntu Using Xmodmap
I really did deserve to be slapped for cleaning my laptop keyboard using water. My punishment was a bunch of dead keys, including the left arrow key. This is really annoying, and as it happens they simply don't stock replacement keyboards for my laptop in Lima. I searched everywhere.
With no other real option than to remap my broken keys I stumbled across something really cool in Ubuntu / Linux. Xmodmap is a utility I had used before for remapping dead keys, but I wasn't aware of the Mode_switch modifier which basically acts as an additional Control / Shift button.
The magic happens when you map Mode_switch to the otherwise useless Caps Lock key. Voila! Instantly you have a whole new set of shortcuts available using Caps Lock that you can use for ALL your applications. I've set up VIM style navigation keys, and shortcuts for hard to reach common keys like escape, backspace, delete, page up and page down.VIM Key Bindings In Ubuntu Using Xmodmap
It's freaking awesome. I haven't even removed my hands from touch typing position to type this entire article into the browser even though I've been making errors and scrolling around the article to edit it.
VIM navigation uses h l j and k respectively for left, right, up and down. It's fantastic for programming but also great for web browsing, word-processing and spreadsheets. I never realised how often I reached for the mouse just to scroll through a document.
Having backspace on your fingertips is a huge time saver too, and as a bonus, I've also mapped Caps-G the a mouse click so I don't have to remove my thumb from the trackpad when I use it.
Here is the xmodmap script I'm using. To run the script just save it and execute "xmodmap <filename>". You need to enable keyboard control of the mouse in your settings for the mouse-click shortcut to work.
! use caps lock as additional modifier clear Lock keycode 66 = Mode_switch ! application shortcuts keycode 54 = c C Escape keycode 58 = m M Return keycode 40 = d D Delete keycode 41 = f F BackSpace keycode 42 = g G Pointer_Button1 ! navigation shortcuts keycode 29 = y Y Home keycode 30 = u U Next keycode 31 = i I Prior keycode 32 = o O End keycode 43 = h H Left keycode 44 = j J Down keycode 45 = k K Up keycode 46 = l L Right
Basically, the three settings for each key are the unmodified, Shift-modified and Caps-modified (i.e. Mode_switch) output for each key. In the case that your keycodes are different to mine, you can use "xev" to test your keyboard's keycodes.
Roger Keays is an artist, an engineer, and a student of life. He has no fixed address and has left footprints on 40-something different countries around the world. Roger is addicted to surfing. His other interests are music, psychology, languages, the proper use of semicolons, and finding good food.