Overview
I spend a lot of time on a computer. Much of this time is spent doing tasks like typing LaTeX, typing R code, and typing HTML. Regardless of what I'm doing I often need to switch between typing text and navigating the cursor. I long ago realised that moving the hands between the home keys (i.e., JKL;) and the mouse was slower than moving the hands between the home keys and the navigation keys (e.g., left, right, Home, etc.). However, I wanted something quicker. Moving the hands between the home keys and the cursor keys takes time and it is also slightly disruptive to attention. I was aware of some of the key bindings used in text editors such as Emacs and Vi that allowed typing and navigation to occur without moving the hands away from the home key position. However, I wanted to have a standard set of keys that would work across all program on Windows.This led me to use AutoHotKey to bind the navigation keys to more accessible keys. This post sets out the key bindings that I chose. It also sets out the AutoHotKey script in case you wanted to implement it.
The new bindings took about a week to be useful, a month to feel natural, and about three months to feel completely automatic. The bindings are more efficient than my old strategy of moving between the cursor keys and the home keys.
Choosing Keys to Bind
The choice of keys to bind was a critical one. I used the following principles for bindings:- Bindings should not override important existing bindings
- Bindings should require minimal effort
- Bindings should facilitate transfer from skills with traditional layout
- Bindings should integrate with important key combinations such as Ctrl+Left, Ctrl+Shift+Left
Windows Key
as the modifier to activate navigation mode.
I chose the following bindings for the navigation keys.
J - Down K - Up L - Left ; - Right H - Home N - End U - Del I - Page Down O - Page UpThus, for example, if I want to move the cursor to the left, I press
WindowsKey+L
;
if I want to move the cursor one word to the left, I press WindowsKey+Ctrl+L
;
if I want to highlight one word to the right, I press WindowsKey+Ctrl+Shift+;
.
Issues
There were a couple of initial implementation issues which I resolved.1. Windows Key and the Start Menu
One issue with using theWindows Key
as a modifier key is that
it often triggers the Start Menu.
To solve this problem, I added the following commands to my AutoHotKey script (see below).
~LWin Up:: return ~RWin Up:: returnIf I need to actually use the Start Menu from the keyboard I just press
Ctrl+Esc
.
2. Problems with binding
On my old laptop (5 years old), the key bindings sometimes failed to work. For example, the letterL
would be printed when I intended to navigate left.
I have not had this issue since updating my laptop.
3. Combining with modifier keys
When first adopting the keys, I wasn't sure which fingers to use for the modifier keys.After some experimentation I adopted the following. In general I use my left ring finger to press the
Windows Key
.
When I need to select text, I use the left little finger for the Control Key
,
left ring finger for the Shift Key
, and the left thumb for the Windows Key
.
Implementing in AutoHotKey
The following procedure sets out how to set up the key bindings using AutoHotKey.1. Download and Install AutoHotKey
AutoHotKey is a free download and is available here.2. Disable Windows + L
If you are running Windows 7,Windows+L
logs you off the computer.
To disable this feature, see the
following post on HowToGeek.
In summary to disable this feature:
1. Start regedit: e.g., press Windows+R and type "regedit"
2. Navigate to the following folder
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\System
3. Then "On the right-hand side, create a new DWORD 32-bit value named DisableLockWorkstation and give it one of these values: 1 – Disable Lock Workstation 0 – Enable Lock Workstation" (i.e., 1 to disable)
3. Set up the AutoHotKey Script
Copy the following code into a text file and give it a name like "newkeybindings.ahk". Double click on the file to check that it works. If you want the key bindings to be made permanently, add a shortcut to the file to your Startup folder (i.e., Start Menu - Programs - Startup).#space:: SendInput {Space} return ~LWin Up:: return ~RWin Up:: return #l:: SendInput {Left} return #j:: SendInput {Down} return #;:: SendInput {Right} return #k:: SendInput {Up} return #u:: SendInput {Delete} return #h:: SendInput {Home} return #n:: SendInput {End} return #o:: SendInput {PgUp} return #i:: SendInput {PgDn} return #+l:: SendInput +{Left} return #+j:: SendInput +{Down} return #+;:: SendInput +{Right} return #+k:: SendInput +{Up} return #+u:: SendInput +{Delete} return #+h:: SendInput +{Home} return #+n:: SendInput +{End} return #^+h:: SendInput ^+{Home} return #^+n:: SendInput ^+{End} return #+o:: SendInput +{PgUp} return #+i:: SendInput +{PgDn} return #^l:: SendInput ^{Left} return #^j:: SendInput ^{Down} return #^;:: SendInput ^{Right} return #^k:: SendInput ^{Up} return #^u:: SendInput ^{Delete} return #^h:: SendInput ^{Home} return #^n:: SendInput ^{End} return #^o:: SendInput ^{PgUp} return #^i:: SendInput ^{PgDn} return #+^l:: SendInput +^{Left} return #+^j:: SendInput +^{Down} return #+^;:: SendInput +^{Right} return #+^k:: SendInput +^{Up} return #+^u:: SendInput +^{Delete} return #!l:: SendInput !{Left} return #!j:: SendInput !{Down} return #!;:: SendInput !{Right} return #!k:: SendInput !{Up} return #+!l:: SendInput +!{Left} return #+!j:: SendInput +!{Down} return #+!;:: SendInput +!{Right} return #+!k:: SendInput +!{Up} return #^!l:: SendInput ^!{Left} return #^!j:: SendInput ^!{Down} return #^!;:: SendInput ^!{Right} return #^!k:: SendInput ^!{Up} return #+^!l:: SendInput +^!{Left} return #+^!j:: SendInput +^!{Down} return #+^!;:: SendInput +^!{Right} return #+^!k:: SendInput +^!{Up} return
Hi Jeromy,
ReplyDeleteThanks for this posting. How do you open marked files with notepad and emacs by shortcuts? I tried with this autohotkey-code:
****************************
#n::Run("notepad.exe")
#c::Run("runemacs.exe")
Run(OpenWith) {
Clipboard =
Send ^c
ClipWait
Run, % OpenWith " " Clipboard
Return
}
****************************
It works with notepad but not with emacs. Emacs starts but the text won't fill into emacs. Maybe you know how to do.
Hi Giordano,
ReplyDeleteI don't use Emacs (yet?); so I'm not sure how you pass files to it on the command line in Windows.
I imagine if you post the question on SuperUser.com or possibly StackOverflow.com you might get a good answer.
Thanks. I was in another forum but did'nt get help. I will try with SuperUser.
ReplyDelete"J - Down
ReplyDeleteK - Up
L - Left
; - Right"
Sacrilege to Vim users! *Everybody* knows it should be:
"J - Down
K - Up
H - Left
L - Right"!
I found this page, incidentally, because I was looking for anyone that might have happened to have created Vim keybindings for AutoHotKey in order to have at least a sort of cut-down Vim with all their applications. I wonder how much of Vim functionality is possible with AHK, within reason (i.e.,without essentially rewriting Vim all over again).
I wrote this post quite a while ago now. Since then I have learnt Vim:
Deletehttp://jeromyanglim.blogspot.com.au/2011/01/reasons-for-transitioning-to-vim.html
I guess this post was a stopping point on the journey to Vim.
Have you checked out Kommand? It is also written in AHK: - http://www.autohotkey.com/community/viewtopic.php?p=281279
ReplyDeleteHere is the author page : http://www.kylirhorton.com/2009/kommand/
Also, I found this as well : http://github.com/mihaifm/vim.ahk
Please update the post with any changes you've made (hjkl instead of jkl;?). Your post is in one of the top pages in Google.
Thank you for writing this
Do you still use this system for everything outside of Vim? I have a Vim based system similar to yours that I use in all programs (with most Vim commands that can be created using AutoHotkey, which include most of them, many more than you list here and similar to http://github.com/mihaifm/vim.ahk and https://autohotkey.com/board/topic/42706-kommand-a-cross-application-vim-like-hot-key-solution/).
ReplyDeleteMuch has changed. I now use OSX now. I still use vim a bit for markdown files. I also use Vim mode in RStudio.
Delete