その手の平は尻もつかめるさ

ギジュツ的な事をメーンで書く予定です

Karabiner-Elementsでcolonとsemicolonを入れ替える

[追記]
コメントで指摘がありましたが,Karabiner-ElementsのGUI上で
complex modifications → Add rule → import more rules from the Internet → Exchange semicolon and colon
を選択することで所望の動作の実現が可能なようです.

従って本記事はcolonとsemicolonを入れ替えるというよりも,任意のキーを入れ替える時のためのtipsとなります.
[追記ここまで]

MacのUSキーボードの話です.

Karabinerにはcolonとsemicolonを入れ替えるという項目があり,これが大変便利だったのですが (特にvimを使っているときとかに便利),Karabiner-Elementsではこのオプションがありません.現時点では,macOS Sierra上だとKarabiner-Elementsを使うほかないので,つまりGUI上からcolonとsemicolonをswapする方法がありません.

そもそもcolonとsemicolonを入れ替えて使うというのがアレなので,Sierraに移行したのを機に元に戻すことも考えたのですが,しかし入れ替えた環境に慣れてしまっているので難しい.なんとかしたい.というわけで以下を ~/.config/karabiner/karabiner.json に書き込むと入れ替えができる.

{
    "global": {
      ...
    },
    "profiles": [
        {
            "complex_modifications": {
                ...,
                "rules": [
                    {
                        "description": "Swap colon and semicolon",
                        "manipulators": [
                            {
                                "type": "basic",
                                "from": {
                                    "key_code": "semicolon",
                                    "modifiers": {
                                        "optional": [
                                            "caps_lock"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "semicolon",
                                        "modifiers": [
                                            "left_shift"
                                        ]
                                    }
                                ]
                            },
                            {
                                "type": "basic",
                                "from": {
                                    "key_code": "semicolon",
                                    "modifiers": {
                                        "mandatory": [
                                            "shift"
                                        ],
                                        "optional": [
                                            "caps_lock"
                                        ]
                                    }
                                },
                                "to": [
                                    {
                                        "key_code": "semicolon"
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            ...
        }
    ]
}

profiles.complex_modifications.rules の中身をこのように書くと所望の挙動となる.よかったよかった.

他のキーの入れ替えについてもこれと同様な感じで書き込むといけそうで良いですね.