0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Karabinerの便利な機能を使おう

Posted at

#complex_modifications
動機:macbookのぺたぺたキーボードに耐えかねて外付けキーボードを買ったのでいろいろ便利に設定したかった.
問題:痒いところに手を届かせたいのにimportできるルールが微妙

 というわけでcomplex_modificationsに自作のjsonファイルを放り込むことにした.
 とりあえずcaps_lock単押しをreturnに変えて,長押し中の挙動を設定した.(iとoを文字削除に当てたがこれが意外と快適)
 シェルスクリプトを埋め込めるので,選択範囲のurlを開いたり検索したりできるようにした.(結構雑)
 他にもいろいろ設定したが,環境依存がありそうなのと量が多いのとで今回は割愛.(半角/全角キーとかいらないからfnキーに変えてごちゃごちゃやってる)

 参考までに代表的な部分だけ抽出したのが下のやつ.

sample_caps.json
{
  "title": "caps_lock modification",
  "rules": [
    {
      "description": "[Vim-like mode] trigger: <caps_lock> held down",
      "manipulators": [
        {
          "type": "basic",
          "from": {
            "key_code": "caps_lock"
          },
          "parameters": {
            "basic.to_if_alone_timeout_milliseconds": 200,
            "basic.to_if_held_down_threshold_milliseconds": 10
          },
          "to_if_alone": [
            {
              "key_code": "return_or_enter"
            }
          ],
          "to_if_held_down": [
            {
              "set_variable": {
                "name": "vim_mode",
                "value": 1
              }
            }
          ],
          "to_after_key_up": [
            {
              "set_variable": {
                "name": "vim_mode",
                "value": 0
              }
            }
          ]
        }
      ]
    },
    {
      "description": "------- [Vim-like mode] hjkl => arrow",
      "manipulators": [
        {
          "from": {
            "key_code": "h",
            "modifiers": {
              "optional": [
                "any"
              ]
            }
          },
          "to": [
            {
              "key_code": "left_arrow"
            }
          ],
          "conditions": [
            {
              "name": "vim_mode",
              "type": "variable_if",
              "value": 1
            }
          ],
          "type": "basic"
        }
      ]
    },
    {
      "description": "------- [Vim-like mode] yuiop => copy, cut, backspace, delete, paste",
      "manipulators": [
        {
          "from": {
            "key_code": "y"
          },
          "to": [
            {
              "key_code": "c",
              "modifiers": [
                "left_command"
              ]
            }
          ],
          "conditions": [
            {
              "name": "vim_mode",
              "type": "variable_if",
              "value": 1
            }
          ],
          "type": "basic"
        }
      ]
    },
    {
      "description": "------- [Vim-like mode] tab,space => option, escape",
      "manipulators": [
        {
          "from": {
            "key_code": "tab"
          },
          "to": [
            {
              "key_code": "left_option",
              "modifiers": []
            }
          ],
          "conditions": [
            {
              "name": "vim_mode",
              "type": "variable_if",
              "value": 1
            }
          ],
          "type": "basic"
        }
      ]
    },
    {
      "description": "------- [Vim-like mode] gf => launch, find (Chrome)",
      "manipulators": [
        {
          "from": {
            "key_code": "g"
          },
          "to": [
            {
              "shell_command": "open -a 'Google Chrome.app'"
            }
          ],
          "conditions": [
            {
              "name": "vim_mode",
              "type": "variable_if",
              "value": 1
            }
          ],
          "type": "basic"
        },
        {
          "from": {
            "key_code": "f"
          },
          "to": [
            {
              "key_code": "c",
              "modifiers": [
                "left_command"
              ]
            },
            {
              "shell_command": "sleep 0.1; open \"$(pbpaste)\" || open \"https://www.google.com/search?q=$(pbpaste | ruby -e 'require \"cgi\"; print CGI.escape($<.read.chomp)')\""
            }
          ],
          "conditions": [
            {
              "name": "vim_mode",
              "type": "variable_if",
              "value": 1
            }
          ],
          "type": "basic"
        }
      ]
    }
  ]
}

 これを下のディレクトリに放り込めばkarabinerから追加できる.

$HOME/.config/karabiner/assets/complex_modifications
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?