💨

Macに設定したこと色々

に公開

設定したことをメモ代わりに

全角 <-> 半角を C-oに

設定 -> キーボード -> キーボードショートカット -> 入力ソース

前の入力ソースを選択 を C-o にする

ファンクションキー有効化

設定 -> キーボード -> キーボードショートカット -> ファンクションキー

あんまファンクションキーつかわないな、、、

【】の入力

設定じゃないけど、、、WindowsのIMEだとセットで変換してくれるけどしてくれないので

全角にして Option + 8, Option + 9

Karabina祭り

Windowsでは、keyhac使ってきたけどMacはKarabinaで。

JSONでここまでするってすごいの一言。。。。

まぁ、KeyhacもキーバインドをPythonって定義ってのはすごいが、、

半角\をデフォルトに

デフォルトだと ¥ なので、うっとおしい。

元ネタ

  • Complex Mofifications 選択
  • Add predefined rule 選択
  • Import more rules from the Internet 選択
  • 検索窓に "Swap ¥ and \ always on JIS Keyboards" と打つ
    Swap ¥ and \ always on JIS Keyboards の横のImportクリックするとKarabinaが開く
  • 以下二つを有効化
    Change ¥ to Alt+¥
    Change Alt+¥ to ¥

Windowsでは、半角の¥が打てないので、ここでは全角としてるけど、実際は半角で

中身はこんな感じ

{
  "title": "Swap ¥ and \\ always on JIS Keyboards",
  "rules": [
    {
      "description": "Change ¥ to Alt+¥",
      "manipulators": [
        {
          "from": {
            "key_code": "international3"
          },
          "to": [
            {
              "key_code": "international3",
              "modifiers": [
                "option"
              ]
            }
          ],
          "type": "basic"
        }
      ]
    },
    {
      "description": "Change Alt+¥ to ¥",
      "manipulators": [
        {
          "from": {
            "key_code": "international3",
            "modifiers": {
              "mandatory": [
                "option"
              ]
            }
          },
          "to": [
            {
              "key_code": "international3"
            }
          ],
          "type": "basic"
        }
      ]
    }
  ]
}

キーバインドをEmacsに

Macのキーバインドは概ねEmacsなのでいいんだけど、set-markがなかったり、C-kがクリップボードと連携してないなど、惜しいので、以下を導入

元ネタ

GhosttyをEmacs modeの対象外に

ターミナルで、Emacsを使うので、Emacs modeは無効化する。
これは、そこそこ地獄。。。

"conditions": [
  {
    "type" : "frontmost_application_unless"
    "bundle_indentifiers": [
      "^com\\.mitchellh\\.ghostty$"
    ]
  }
]

bundle_identifiersは既にEmacs modeに定義されているので、そこに "^com\\.mitchellh\\.ghostty$" を追加していく。

手で変えたが中々の数があるので、シンドイ

C-cでコピー

ここから独自。

${HOME}/.config/karabiner/assets/complex_modifications

の中に適当なJSONファイルを作って、独自の定義はまとめておくと管理しやすいかも。

複数のルールを1ファイルにまとめる場合は、以下のようにまとめる。

{
  "title": "ほげほげ",
  "rules": [
    この中に以下のJSONを書く
  ]
}
{
  "description": "Ctrl-c to copy",
  "manipulators": [
    {
      "from": {
        "key_code": "c",
        "modifiers": {
          "mandatory": [
            "left_control"
          ]
        }
      },
      "to": [
        {
          "key_code": "c",
          "modifires": [
            "command"
          ]
        }
      ],
      "conditions": [
        {
          "type": "frontmost_application_unless",
          "bundle_identifires": [
            "^com\\.mitchellh\\.ghostty$"
          ]
        }
      ],
      "to_after_key_up": [
        {
          "set_variable": {
            "name": "emacs_mode_markset",
            "value": 0
          }
        }
      ],
      "type": "basic"
    }
  ]
}

to_after_key_upは、Emacs modeの関連。

コピーしたら、marksetモードを戻してあげるためのもの。

C-t -> Command-t, C-l -> Command-l

両方ともブラウザのショートカット

C-t: 新規タブ
C-l: アドレスバーを選択

一個前のコピーのfrom, toを変えるだけ。

to_after_key_upはいらない

補足

アプリケーション名の調べ方

"^com\.mitchellh\.ghostty$" などのアプリケーション名はKarabiner-EventViewerで分かる

Karabiner-EventViewer起動後、Frontmost Applicationを選択して対象のアプリケーションを起動するなり、選択してあげれば画面に表示される

frontmost_application_unless の反対

反対?

frontmost_application_if

https://karabiner-elements.pqrs.org/docs/json/complex-modifications-manipulator-definition/conditions/frontmost-application/

Discussion