Help us understand the problem. What is going on with this article?

Karabiner-Elementsで、MacのTerminalでoptionとcommandを入れ替え・自由にキーバインド変更をする例

More than 1 year has passed since last update.

Mac Sierraでキーボードの入力設定が変更できるKarabiner-Elementsが、待ち望んでいたアプリケーション別のキーバインド入れ替えに対応しました。
ここでは、よく使うTerminalアプリのみで、キーボード入力を入れ替える方法を紹介します。

なお、公式でいろいろなjsonサンプルがあるため、参考にするといろいろな事ができるかと思われます。
https://pqrs.org/osx/karabiner/complex_modifications/#application_specific

Karabiner-Elements インストール方法

makeするために、 boost と、 Xcode Command Line Tools を入れる必要があります。

  • boost
    • brew install boost
  • Xcode Command Line Tools
    • XCodeをApple Storeから入れた後、XCodeのメニューよりインストールが出来ます。
  • Karabiner-Elements
    • git clone https://github.com/tekezo/Karabiner-Elements.git
    • make

commandとoptionを入れ替える

Terminalのみ入れ替えをするには、 $HOME/.config/karabiner/assets/complex_modifications/terminal.json ディレクトリ下に以下のjsonファイルを置きます。

$HOME/.config/karabiner/assets/complex_modifications/terminal.json
{
  "title": "ALT <=> CMD in Terminal",
  "rules": [
    {
      "description": "Swap option and command in Terminal",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "left_option",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_command"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "Terminal"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "left_command",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_option"
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "Terminal"
              ]
            }
          ]
        }
      ]
    }
  ]
}

Karabiner-Elements に反映させたあと、[Complex Modifications]->[Rules]の下にある[Add rule]をクリックし、[Swap option and command in Terminal]の[Enable]をクリックします。

スクリーンショット 2017-08-07 16.31.01.png

追加項目が表示されない場合はjsonファイルが反映されていない可能性があるので、Karabiner-Elementsを起動し直して下さい。

自由にキーバインドを登録する

Terminal アプリで誤爆が多かった、Cmd+f, Cmd+b, Cmd+d を、それぞれ、 Option+f, Option+b, Option+d に入れ替えるソースを書きました。

{
  "title": "ALT <=> CMD in Terminal",
  "rules": [
    {
      "description": "Swap command [f b d] to alt [f b d] in Terminal",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "f",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "f",
              "modifiers": [
                "left_option"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "Terminal"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "b",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "b",
              "modifiers": [
                "left_option"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "Terminal"
              ]
            }
          ]
        },
        {
          "type": "basic",
          "from": {
            "key_code": "d",
            "modifiers": {
              "mandatory": [
                "command"
              ],
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "d",
              "modifiers": [
                "left_option"
              ]
            }
          ],
          "conditions": [
            {
              "type": "frontmost_application_if",
              "bundle_identifiers": [
                "Terminal"
              ]
            }
          ]
        }
      ]
    }
  ]
}
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away