1
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?

Karabiner-Elementsでwindows-likeとemacs-likeの2つのキーバインドを使い分ける 2025年版

Last updated at Posted at 2025-01-14

MacのKarabiner-Elementsでwindows-likeとemacs-likeの2つのキーバインドを使い分けるにはどうするのかに関するメモ。

やりたいこと:普段のWEBブラウザ等ではwindows-likeなキーバインド(Ctrl-c,Ctrl-vでコピーペーストCtrl-fで検索)を使い、terminalやEmacsではそのキーバインドをやめたい(Ctrl-w,Ctrl-yでコピーペースト、Ctrl-sで検索)。

2020年に同じことを書いたがKarabiner-Elementsが更新されていろいろ使いやすくなっているので更新する。

手順1: Karabiner-Elementsをインストールする

Karabiner-Elementsをインストールする。
https://karabiner-elements.pqrs.org/
上記のURLからダウンロードしてくる。本記事執筆時点ではversion 15.3.0である。

手順2: Karabiner-Elementsの使い方を理解する

まず、Karabiner-Elementsを起動してComplex modificationsタブを選択する。

次にAdd predefined ruleボタンを押したのちWindows shortcuts on macOSを検索しとりこむ。

スクリーンショット 2025-01-14 20.51.58.png

これでルール集を取り込めるが、まだそのルール集の中のどのルールを実際に使うのかを決めていない。実際に使うルールをEnableする。例えばCtrl+C, Ctrl+P, Ctrl+X => Cmd+C (Copy), Cmd+v (Paste), Cmd+X (Cut)をEnableにするとその瞬間からばCtrl+CがCmd+Cに変換されて、ブラウザ等のテキストがコピーできるようになる。まずはそこまで確認すること。

そして、この設定でEmacsを開いて編集しようとするとおかしなことになることに気づくはず。例えばCtrl-x Ctrl-fでファイルを開こうとすると最初のCtrl-xがCmd-xに変換されてしまうのでうまく開けなくなる。

手順3: アプリケーションごとにキーバインドを変えるためルールを編集する

この操作2020年版より簡単になっている。上記のルールでEditを押すと詳細が編集できる。Windows shortcuts on macOSにはこのショートカットを適用しないアプリがあらかじめ書いてあるのでそこに必要なアプリを追加する。設定をよくみると以下のような箇所が見つかるはずである。このconditionsの中の"bundle_identifiers"に書かれているアプリではこのショートカットは適用されない。

            "conditions": [
                {
                    "bundle_identifiers": [
                        "^org\\.gnu\\.Emacs$",
                        "^com\\.apple\\.Terminal$",
                        "^com\\.utmapp\\.UTM$",
                        "^com\\.microsoft\\.rdc$"
                                            ],
                    "type": "frontmost_application_unless"      
                }
            ],

アプリケーションのBundle Identifierを調べるには、Karabiner-Elementsをインストールしたときに同時にインストールされるKarabiner-EventViewerを使用する。このアプリケーションを起動し、Frontmost applicationタブを選べばクリックしたアプリケーションのBundle Identifierを教えてくれる。
スクリーンショット 2025-01-14 21.18.46.png

2020年版に比べて極めて簡単になっているのがわかると思う。

1
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
1
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?