Kentaro Kuribayashi's blog

Software Engineering, Management, Books, and Daily Journal.

進化したKarabinar-Elementsで、Ctrl-[と同時に変換モードを英数に戻す

Karabiner-Elements が超絶怒濤に進化している。今も!という記事で知ったのですが、キーカスタマイズソフトのKarabinarの、macOS Sierraへの対応バージョンであるところのKarabiner-Elementsがあれこれできるようになっていて、僕の要求についてはすべて満たせるようになっていました。

その要求とはすなわち:

  • SandS
  • Ctrl-mでReturn
  • Ctrl-[PNBF]で↑↓←→
  • Ctrl-[でEsc
  • iTerm上のVimで、インサートモードから抜ける時にIMEを英数に戻す(Vim使いの人は、これのありがたみがわかると思います)

なのですが、macOS Sierra + Keyhacでキーバインドをカスタマイズという記事を書いたときにはKarabinar-Elementsではできなかったものが、いまはできるようになっています。めちゃ便利ー。

SandSやEmacsモードについては、設定画面からKarabiner-Elements complex_modifications rulesを開いて、そこからクリックひとつで設定をインポートできるようになってる!すごい!

「iTerm上のVimで、インサートモードから抜ける時にIMEを英数に戻す」という要件については、僕はいまはVSCode(+Vimプラグイン)を使っているのだけど、それも合わせて、Terminal.app、iTerm、VSCodeで実現するなら、以下のような設定を ~/.config/karabiner/karabiner.json に足せばOKです。

{
    "description": "Esc with convert input mode to eisuu",
    "manipulators": [
        {
            "from": {
                "key_code": "open_bracket",
                "modifiers": {
                    "mandatory": [
                        "control"
                    ],
                    "optional": [
                        "caps_lock"
                    ]
                }
            },
            "to": [
                {
                    "key_code": "escape"
                },
                {
                    "key_code": "semicolon",
                    "modifiers": [
                        "control",
                        "left_shift"
                    ]
                }
            ],
            "conditions": [
                {
                    "type": "frontmost_application_if",
                    "bundle_identifiers": [
                        "^com\\.apple\\.Terminal$",
                        "^com\\.googlecode\\.iterm2$",
                        "^com\\.microsoft\\.VSCode$"
                    ]
                }
            ],
            "type": "basic"
        }
    ]
}