TerminalやMacVimでEsc (or ^[)キーで日本語IMEを英数に切り替える(Karabiner-Elementsによる設定)


Karabiner-ElementsがVersion 0.91.6となって、待望の「アプリケーション毎のキーバインディング」がサポートされました。

macOS SierraでKarabinerが使えなくなって以来、私のようなVimユーザにとって「ESCキーで日本語入力をOFFにする」設定が何かと不便で困っていましたが、今回のKarabiner-ElementsのアップデートでなんとかKarabiner時代と同様の設定が可能となりました。有り難し!

設定方法

$ vim ~/.config/karabiner/assets/complex_modifications/FromEscapeToJapanese_eisuu.json

このFromEscapeToJapanese_eisuu.jsonファイルに次の内容を記述して保存。1

FromEscapeToJapanese_eisuu.json
{
  "title": "Terminal等でESCあるいは^[で日本語入力を英数に",
  "rules": [
    {
      "description": "TerminalまたはMacVimでESCあるいは^[を押したときに日本語入力を英数に切り替える。",
      "manipulators": [
        {
          "type": "basic",
          "from": { "key_code": "escape", "modifiers": { "optional": [ "any" ] } },
          "to": [ { "key_code": "japanese_eisuu" }, { "key_code": "escape" } ],
          "conditions": [ { "type": "frontmost_application_if", "bundle_identifiers": [ "^com\\.apple\\.Terminal$", "^org\\.vim\\." ] } ]
        },
        {
          "type": "basic",
          "from": { "key_code": "open_bracket", "modifiers": { "mandatory": ["left_control"] } },
          "to": [ { "key_code": "japanese_eisuu" }, { "key_code": "escape" } ],
          "conditions": [ { "type": "frontmost_application_if", "bundle_identifiers": [ "^com\\.apple\\.Terminal$", "^org\\.vim\\." ] } ]
        }
      ]
    }
  ]
}
  • Karabiner-Elements PreferencesウィンドウでComplex Modificationsメニューを開く

  • 左下の"Add rule"をクリックすると次のような設定可能なルールの一覧が表示される。

  • "ESCを押したときに日本語入力を英数に切り替える。"の右にある"Enable"をクリックする。

  • "Complex Modifications"ウィンドウで当該ルールが追加されていることを確認。

以上で設定は終わりです。



  1. ここでは、TerminalアプリとVimアプリの起動時のみ有効になるように設定しています。他のアプリのbundle identifiersを調べたい場合は、Karabiner-ElementsのメインメニューからEventViewerを起動して"Frontmost Application"から調べることができます。