【Karabiner Elements】 macのおすすめキーマップを紹介

この記事は、Gajeroll Advent Calendar 2022 の 9 日目の記事です。
コーディングの生産性向上に欠かせないキーマップ変更。
Karabiner Elements を使った、反則級のキー配列を教えましょう。
Karabiner Elements をインストール
公式サイトから最新版をインストールします。
キー入力を監視するための権限の付与も必要になります。
指示にしたがって操作すれば問題ないでしょう。
基本的な使い方
Simple Modifications → For all devices の中で、Add item をクリックします。
左側にこれまでのキーを、右側に変更後のキーを設定します。
基本的には For all devices で問題ありません。
しかし融通がきかないキーボードがあれば、個別のキーボードを選択して設定しましょう。
これにより、特定のキーボードにキーマップ変更を上書きすることができます。
さらに Complex Modifications や JSON ファイルの編集により、もっと細かい設定もできます。
おすすめの設定
BackSpace⌫ を左小指に配置
caps_lock → delete_or_backspace
CapsLock を使わないユーザー向けです。
その場合、CapsLock に BackSpace を割り当てましょう。
これでタイプミスをしてもすぐに修正できるので、タイピングの効率が爆上がりします。
これまでのキー配列にはもう戻れません。
コーディングで Tab キーをよく使う場合は、CapsLock を Tab に、Tab を BackSpace に変えるのがおすすめです。
変更の仕方は次のようになります。
caps_lock → tab
tab → delete_or_backspace
これによって小指の少ない移動で Tab キーが押せるようになります。
mac に Delete⌦ を降臨させる
delete_or_backspace → delete_forward
先程の設定で本来のバックスペースが手持ち無沙汰になったので、そこを Delete キーに変えてしまいましょう。
すると mac に Delete キーが登場します。
Tab キーと同時押しで矢印・数字を入力
JSON ファイルを編集することでより高度な設定ができます。
以下のコードを ~/.config/karabiner/assets/complex_modifications
の直下に置きます。
Complex Modifications → Add rule → Arrows and Numbers → Enable で有効化できます。
Tab
+ 左手ホームポジション(EDSF
)で上下左右の矢印キーになります。
そして Tab
+ 右手ホームポジション(7890UIOPJKL;NM./
)でテンキーになります。
JSON コード
{
"title": "Arrows and Numbers",
"rules": [
{
"description": "Arrows and Numbers",
"manipulators": [
{
"from": {
"key_code": "tab"
},
"to": [
{
"set_variable": {
"name": "numbers_mode",
"value": 1
}
}
],
"to_after_key_up": [
{
"set_variable": {
"name": "numbers_mode",
"value": 0
}
}
],
"to_if_alone": [
{
"key_code": "tab"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "7"
},
"to": [
{
"key_code": "delete_or_backspace"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "8"
},
"to": [
{
"key_code": "keypad_equal_sign"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "9"
},
"to": [
{
"key_code": "keypad_slash"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "0"
},
"to": [
{
"key_code": "keypad_asterisk"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "u"
},
"to": [
{
"key_code": "keypad_7"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "i"
},
"to": [
{
"key_code": "keypad_8"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "o"
},
"to": [
{
"key_code": "keypad_9"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "p"
},
"to": [
{
"key_code": "keypad_hyphen"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "j"
},
"to": [
{
"key_code": "keypad_4"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "k"
},
"to": [
{
"key_code": "keypad_5"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "l"
},
"to": [
{
"key_code": "keypad_6"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "semicolon"
},
"to": [
{
"key_code": "keypad_plus"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "m"
},
"to": [
{
"key_code": "keypad_1"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "comma"
},
"to": [
{
"key_code": "keypad_2"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "period"
},
"to": [
{
"key_code": "keypad_3"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "slash"
},
"to": [
{
"key_code": "keypad_enter"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "n"
},
"to": [
{
"key_code": "keypad_0"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "e"
},
"to": [
{
"key_code": "up_arrow"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "d"
},
"to": [
{
"key_code": "down_arrow"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "s"
},
"to": [
{
"key_code": "left_arrow"
}
],
"type": "basic"
},
{
"conditions": [
{
"name": "numbers_mode",
"type": "variable_if",
"value": 1
}
],
"from": {
"key_code": "f"
},
"to": [
{
"key_code": "right_arrow"
}
],
"type": "basic"
}
]
}
]
}
有効化するのを忘れないようにしましょう。
Windows ユーザーへ
left_control → left_command
left_command → left_control
Windows マシンに慣れている方は、Command キーのカスタマイズもおすすめです。
これだけで一気に mac が使いやすくなります。
日本語配列ユーザーへ
Windows の日本語配列では、 Shift
+ _
で \
を入力することができます。
これを mac の日本語配列で再現するためのコードがこちらです。
こちらも ~/.config/karabiner/assets/complex_modifications
の直下に置きます。
Complex Modifications → Add rule → Underscore to Backslash → Enable で有効化できます。
{
"title": "Underscore to Backslash",
"rules": [
{
"description": "Underscore to Backslash",
"manipulators": [
{
"from": {
"key_code": "international1"
},
"to": [
{
"key_code": "international3",
"modifiers": [
"option"
]
}
],
"type": "basic"
}
]
}
]
}
こちらも有効化するのを忘れないようにしましょう。
US 配列ユーザーへ
ちなみに US 配列を使っているのであれば、⌘ 英かなは必須です。
これで左右のコマンドキーが「コマンド」兼「英数 or かな」に究極進化します。
参考
Karabiner-Element の設定例について - Qiita
Karabiner-Elements complex_modifications rules
最後に
最後までご覧いただきありがとうございます。
PC ロールでは、テクノロジーに関する情報をまとめて発信しています。
また、おすすめのガジェットについて幅広く紹介していく、ガジェロールもあります。
ガジェットやソフトを使うエンジニア・クリエイターはぜひご覧ください。