This post documents my keyboard layout.

Disclaimer: My layout is super weird, so I don’t expect anyone else to use this out of the box. However, I will cover some ergonomic discussion, which hopefully could evoke some new idea for the readers.

§My Keyboard Layout

§Alphabet Layout

I use colemak layout. Did the switch in 2013, and have been using it since. Was it worth it? I don’t know. Try it for yourself.

§UK layout + ZXCB Shift

The physical keyboard layout is UK layout, where there’s one extra key next to the left SHIFT key. (Depending on the language&region a keyboard is designed for, the symbols on it might differ. Mine, bought in Germany, shows “><”. In the standard US layout, the key next to the left Shift is Z.) The reason for that is when I place my hands on the keyboard, there’s a natural angle formed between my arms, in a shape of an inverted V. Therefore, when I curl my fingers, they move towards bottom-left and bottom-right, respectively; IOW, the horizontal components of the moving vector are in opposite direction. However, if you look at the alphabet area in a keyboard, you will notice it’s leaned towards left, kind of like \. Having one extra key between left SHIFT and Z remedies this problem to some extent, because we could remap extra key + ZXCV to ZXCVB. The original B is a bit hard to reach, so one can definitely just ignore it. However, since <BackSpace> is even harder to reach, I remapped B to <BackSpace>, which is semantically reasonable.

§Control the Control

I have been using Linux for around a decade, and done the swap between Capslock and Ctrl almost from day 0 as instructed in blogs floating around in the community. Roughly in the mid of 2014, I started using Mac for mostly entertaining use, while sshing to my Linux box for programming related tasks. One thing I like the most about Mac is the Cmd key, which more or less is like Ctrl in Linux. Since it’s located next to space, I hit it using my thumb, which feels much more natural than using my pinky. Since it’s a modifier key, it’s only used together with another key. Such feeling becomes more obvious. Try hitting the corresponding key combination while performing the same tasks on Linux vs Mac (such as ctrl-w vs cmd-w for closing a tab, ctrl-cxv vs cmd-cxv for basic editing).

§Return of the Return

Inspired by the same reasoning, I also fiddled the right cmd so that my right thumb would not lie around idle. It’s mapped to Return, as it’s probably the most significant key in daily CLI use.

§Tools

Various tools used to achieve above under different OS.

§Linux

Using the Mac magic keyboard:

1
2
$ setxkbmap -model apple -layout us -variant colemak
$ xmodmap ~/.Xmodmap

The content of .Xmodmap:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
! the physical keys on my magic keyboard
! capslock = 66 = 0x42
! shift_l = 50
! shift_r = 62 = 0x3e
! ctrl_l = 37 = 0x25
! cmd_l = super_l = 133 = 0x85
! alt_l = 64 = 0x40
! alt_r = 108

! mod1 = alt
! mod4 = super

clear control
clear mod1
clear mod4
clear lock

keycode 133 = Control_L
keycode 108 = Control_R
keycode 37 = Super_L

add control = Control_L Control_R
add mod1 = Alt_L Alt_R
add mod4 = Super_L

! capslock is mostly useless; however occasionally, I want input IN ALL CAPS...
! shift_l -> capslock
remove Shift = Shift_L
keycode 50 = Caps_Lock
add lock = Caps_Lock

! capslock -> shift
remove Shift = Shift_L
keycode 66 = Shift_L
add Shift = Shift_L

! shift _zxc keys at bottom-left corner
keycode 94 = z
keycode 52 = x
keycode 53 = c
keycode 54 = v
! v -> b;
keycode 55 = b
! b -> <bs>
keycode 56 = BackSpace BackSpace

! layout on my mac keyboard
! <space> <cmd_r> <alt_r>
! cmd_r -> return
keycode 134 = Return

! eject = delete
keycode 169 = Delete

§Mac

I use Karabiner for remapping certain alphabet keys, and the built-in iTerm2 support for remapping modifier keys as I ssh into my Linux. All this can be done using the GUI; no scripts involved.

§Windows

I use sharpkeys for fiddling with win key and alt keys, and autohotkey for getting colemak with ZXC shift.

The AHK script is shown below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
; Colemak layout for AutoHotkey from UK layout

SetBatchLines, -1 ; speeds up script
#SingleInstance force
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
#MaxHotkeysPerInterval 5000
#InstallKeybdHook
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetTitleMatchMode 3 ; Exact matching to avoid confusing T/B with Tab/Backspace.

;1::1
;2::2
;3::3
;4::4
;5::5
;6::6
;7::7
;8::8
;9::9
;0::0
;-::-
;=::=

;q::q
;w::w
e::f

r::p
t::g
y::j
u::l
i::u
o::y
p::;
;[::[
;]::]


;a::a
s::r
d::s
f::t
g::d
;h::h
j::n
k::e
l::i
`;::o
;'::'

; shift zxcv left by one
;\::z
;+\::Z
;~::Z
;+`::~

`::z
z::x
x::c
c::v
n::k

; change UK layout to international
+3::Send {#}
|::~
;~::|
"::@
@::"
#::\

\::`

RAlt::Capslock

RWin::Enter

<!Space::Suspend

LCtrl & Tab::AltTab