【macOS】キーマップとキーボードショートカットの変更設定

最近では、macOS ユーザーは、いくつもの重なって設定されたショートカット機能を「ほぼ無意識」にキーボードから操作することになっています。

当然、衝突したり、意図しない機能が発動されることも多くなります。

まずは、設定箇所をはっきり把握しておきたいです。

 

■ OS 設定 キーボードショートカット「修飾キー」

修飾キー (Modifier Keys) の、それぞれの機能を入れ替えたり、無効化することができます。


System Settings

  ↓

Keyboard

  ↓

Keyboard Shortcuts…

  ↓

Modifier Keys

👉 Macで修飾キーの動作を変更する - Apple サポート (日本) hatena-bookmark

 

■ キーマップ変更アプリ

修飾キー を含めたいろいろなショートカットを作成できます。⌘(command)⇧(shift) キーの左右個別の機能振り分けやカーソルキー、Fn キーなど細かく設定できるサードパーティのアプリです。

有名な2つを挙げておきます。ソースコードはともに GitHub で公開されています。無料です。

👉 Karabiner-Elements hatena-bookmark

👉 ⌘英かな hatena-bookmark

私は、⌘英かな を利用して、英数 ↔ かな の切り替えと カーソルキー のショートカット作成で使用しています。

👉 【macOS】IDE で 矢印 (カーソルキー) を使うと キーボード ホームポジション がずれる件 hatena-bookmark

 

■ OS 設定 キーボードショートカット「アプリショートカット」

OSの設定からアプリごとにショートカットを設定できます。


System Settings

  ↓

Keyboard

  ↓

Keyboard Shortcuts…

  ↓

App Shortcuts

  ↓

All Applications


👉 Mac のキーボードショートカット - Apple サポート (日本) hatena-bookmark

ショートカットに振り分ける機能の名称に関しては、スペースや大文字小文字などきちんと入力する必要があります。そこが面倒です。機能 - 名称 の一覧とかどこかにないでしょうかね。

👉 【macOS】キーボードショートカットの変更は言語設定別でイヤだ!! hatena-bookmark

 

■ 各アプリの設定

ブラウザ や エディタ、IDE など、インストールしたアプリ内の設定からもショートカットの設定ができます。

以下、Android Studio のデフォルトのショートカット。


👉 キーボード ショートカット  |  Android デベロッパー  |  Android Developers hatena-bookmark

Android Studio では、設定から、個別にショートカットの変更ができますが、それらの詰め合わせとなったIDEAプラグインをインストールしてまとめて変更することもできます。

👉 IdeaVim - IntelliJ IDEs Plugin | Marketplace hatena-bookmark
👉 VSCode Keymap - IntelliJ IDEs Plugin | Marketplace hatena-bookmark
👉 macOS For All - IntelliJ IDEs Plugin | Marketplace hatena-bookmark
👉 Emacs Keymap - IntelliJ IDEs Plugin | Marketplace hatena-bookmark

以下、Chrome のデフォルトのショートカット。

👉 Chrome のキーボード ショートカット - パソコン - Google Chrome ヘルプ hatena-bookmark

Chrome では、設定 - エクステンション - ショートカット


chrome://extensions/shortcuts

から、個別のアプリに対してのショートカットを変更できますが、これも以下のような Chrome エクステンションをインストールすると設定しやすいです。

👉 AutoControl: Keyboard shortcut, Mouse gesture - Chrome Web Store hatena-bookmark
👉 Shortkeys (Custom Keyboard Shortcuts) - Chrome Web Store hatena-bookmark
👉 Disable keyboard shortcuts - Chrome Web Store hatena-bookmark

 

■ まとめ

不必要にショートカットをカスタムするのはやめたほうが良さげ。

最小限のカスタムで今の段階でメモ。


1. os settings keyboard modifier keys

  caps lock → control


2. ⌘英かな (os app)

  left command → 英数
  right command → かな
  control + p → arrow up
  control + n → arrow down
  control + f → arrow right
  control + b → arrow left


3. os settings keyboard app shortcuts

  command + v → Paste and Match Style
  shift + command + v → Paste

  ※ Notes.app 向けに paste 2つを入れ替える。


4. app settings

  - Android Studio
    Settings… - Keymap
    → macOS のままにする

  - Chrome
    disable shortcut (chrome extension)
      command + p → Do nothing
      command + d → Do nothing
      command + s → Do nothing

    ※ 英かな切り替え直後の意図しない動作を防ぐ。

指がホームポジションから離れることがずっと気になっていました。

キーマップを自由にカスタマイズできる ⌘英かなKarabiner-Elements を使うことで カーソルキーを使った範囲選択が shift + control + p/n/f/b でできるようになったことで IDEA/Android Studio 上でエディタの Keymap を デフォルトである macOS のまま利用できるようになったことがうれしい。

衝突の警告が多少出ているが、追って調整していけば問題ないでしょう。



【Intellij IDEA / AndroidStudio】コードを縦に揃えて、あるカラムでソートできるプラグイン - String Manipulation

どちらがいいか、考えたことありますよね。


int robert_age = 32;
int annalouise_age = 25;
int bob_age = 250;
int dorothy_age = 56;


int robert_age     = 32;
int annalouise_age = 25;
int bob_age        = 250;
int dorothy_age    = 56;

意見が分かれることは私も知ってます。

コーディングは、自分自身の考えを表現する創造的な方法です。表現したアイデアを難しく見せてしまうようなツールであるのなら、インデントではなく、ツール自体を改善すべきでしょう。

👉 私がコーディングで垂直方向にそろえるインデントをとる理由 | POSTD hatena-bookmark

縦位置は揃っていた方が良いが、別に揃っていなくても我慢できなくはありません。むしろ、縦位置なんて諦めた方が総合的には幸せになれると思います。

👉 変数や配列の縦位置を揃えてはいけない!!(ほとんどの場合は) - Qiita hatena-bookmark

Android アプリ開発時 Gradle Version Catalog で TOML を使う場合に、見づらいので、縦に揃えたくなることありますよね?

idmodule でソートしたくなることありますよね?


そんな AndroidStudio (Intellij IDEA) プラグインがあります。

【AndroidStudio】コードを縦に揃えて、あるカラムでソートできるプラグイン - String Manipulation



Separators として、" " (半角スペース) のみを指定するのがおすすめです。

右上の column index を見ながら、id でソートできます。

【AndroidStudio】コードを縦に揃えて、あるカラムでソートできるプラグイン - String Manipulation

実際にファイルに反映するのも良し、見てチェックだけするのも良し。

便利です。他にも色々できます。

👉 String Manipulation - IntelliJ IDEs Plugin | Marketplace hatena-bookmark
👉 krasa/StringManipulation: IntelliJ plugin - https://plugins.jetbrains.com/plugin/2162 hatena-bookmark


CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)

PyCharm や Intellij IDEA Ultimate の 「Debug」 で見かけました。


/path/to/python3.11 /path/to/Library/Application Support/JetBrains/Toolbox/apps/IDEA-U/ch-0/222.4345.14/IntelliJ IDEA.app.plugins/python/helpers/pydev/pydevd.py --multiprocess --qt-support=auto --client 127.0.0.1 --port 59014 --file /path/to/test.py 
-------------------------------------------------------------------------------
pydev debugger: CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)
pydev debugger: The debugger may still function, but it will work slower and may miss breakpoints.
pydev debugger: Related bug: http://bugs.python.org/issue1666807
-------------------------------------------------------------------------------
Connected to pydev debugger (build 222.4345.14)
pydev debugger: Unable to find real location for: <frozen codecs>
pydev debugger: Unable to find real location for: <frozen importlib._bootstrap>
pydev debugger: Unable to find real location for: <frozen importlib._bootstrap_external>
pydev debugger: Unable to find real location for: <frozen zipimport>
pydev debugger: Unable to find real location for: <string>
pydev debugger: Unable to find real location for: <frozen posixpath>
pydev debugger: Unable to find real location for: <frozen _collections_abc>
pydev debugger: Unable to find real location for: <frozen os>
pydev debugger: Unable to find real location for: <frozen abc>
pydev debugger: Unable to find real location for: <__array_function__ internals>
pydev debugger: Unable to find real location for: <frozen genericpath>
pydev debugger: Unable to find real location for: <frozen io>

以下を Edit Configrations から Interpreter options に追加すれば消える。


-Xfrozen_modules=off

CRITICAL WARNING: This version of python seems to be incorrectly compiled (internal generated filenames are not absolute)

「Run」 や OS の Termnal から実行すると出ない。

IDE に同梱されてる pydevd が古くて、

Debug するスクリプト(インターラプタ) と pydev の バージョン間の相性がイマイチ

という感じか。

非stable な 3.11.x なども、コマンドのオプションとしてつけると消える。

👉 課題 1666807: Incorrect file path reported by inspect.getabsfile() - Python tracker hatena-bookmark
👉 "CRITICAL WARNING" error debugging Python 3.11 code : PY-56939 hatena-bookmark
👉 fabioz/PyDev.Debugger: Sources for the debugger used in PyDev, PyCharm and VSCode Python hatena-bookmark