Sublime Text 4 の設定(2/3) – Key Bindings [for Mac]
Sublime Text の設定エントリー一覧
- Package Control
- Key Bindings
- for Mac(現在のエントリー)
- for Windows
- Settings
Key Bindings とは
Key Bindings
https://www.sublimetext.com/docs/key_bindings.html
- ショートカットキーの割当設定
- JSON形式のファイルで管理されており、自分の好きなように設定を上書きすることができる
- 初期状態ではデフォルトのファイルは編集できないが、後述の事前準備手順を行うことで編集可能になる
- コメントアウトして設定自体を無効化したいときに利用する
- 設定ファイル上の「super」は「cmd」に該当
設定画面の開き方
- ツールバー>Sublime Text>Preferences>Key Bindings
- Package Control>「Prefereces: Key Bindings」を検索
事前準備
デフォルト設定ファイルを編集可能にする
格納場所の準備
- Finderを開く
- cmd+shift+Gで下記ディレクトリへ移動
~/Library/Application Support/Sublime Text/Packages/
- 直下にDefaultディレクトリを作成
設定ファイルの複製&保存
- SublimeTextを開く
- Key Bindingsを開く
- cmd+shift+Sで先程作ったディレクトリへ保存
- cmd+shift+Gで下記入力して移動する
~/Library/Application Support/Sublime Text/Packages/Default
- ファイル名は
Default (OSX).sublime-keymap
- cmd+shift+Gで下記入力して移動する
デフォルト設定ファイルを編集する
Key Bindingsを開いたときに左側にでる「Defaults」のほうを編集する。
Google日本語入力
- 参考記事:OSXのSublimeText3でGoogle日本語入力の不満を解消し、さらにMarkdown環境を整える
- キー割り当てが衝突している箇所をコメントアウトする。
全角カナ変換(F7)
{ "keys": ["f7"], "command": "build" },
- 該当機能:ビルド実行
- 代用キー:cmd+B
ユーザー定義ファイルを編集する
Key Bindingsを開いたときに右側にでる「Users」のほうを編集(追記)する。
ConvertToUTF8がcmd+shift+CでGBKにセットしちゃうのを防ぐ
{ "keys": ["shift+super+c"], "command": "null" }
Reindentのショートカット設定
- cmd+shift+Rでインデント整形できるようにする。
{ "keys": ["super+shift+r"], "command": "reindent" , "args": { "single_line": false } }
個人的な好みでのキー操作設定
Windows用の設定との兼ね合い(操作感の共通化目的)で設定したものたち。
行の入れ替え
{ "keys": ["ctrl+shift+up"], "command": "swap_line_up" },
{ "keys": ["ctrl+shift+down"], "command": "swap_line_down" },
矩形選択
{ "keys": ["ctrl+super+up"], "command": "select_lines", "args": {"forward": false} },
{ "keys": ["ctrl+super+down"], "command": "select_lines", "args": {"forward": true} },
タブ選択
{ "keys": ["super+pageup"], "command": "prev_view" },
{ "keys": ["super+pagedown"], "command": "next_view" },
画面分割
- 3分割以上は設定しない(macOSのキャプチャ機能と競合するため)
- 設定してはいるが、正直「縦に2分割」ぐらいしか使ってない
{
"keys": ["super+shift+1"],//分割なし
"command": "set_layout",
"args":
{
"cols": [0.0, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1]]
}
},
{
"keys": ["super+shift+2"],//縦に2分割
"command": "set_layout",
"args":
{
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 1.0],
"cells": [[0, 0, 1, 1], [1, 0, 2, 1]]
}
},
{
"keys": ["super+shift+alt+2"],//横に2分割
"command": "set_layout",
"args":
{
"cols": [0.0, 1.0],
"rows": [0.0, 0.5, 1.0],
"cells": [[0, 0, 1, 1], [0, 1, 1, 2]]
}
},
{
"keys": ["super+shift+5"],//縦横2分割(4エリア)
"command": "set_layout",
"args":
{
"cols": [0.0, 0.5, 1.0],
"rows": [0.0, 0.5, 1.0],
"cells":
[
[0, 0, 1, 1], [1, 0, 2, 1],
[0, 1, 1, 2], [1, 1, 2, 2]
]
}
},
参考:過去設定していたもの
たぶんSublime Text自体のアプデとかで解消されて対応不要になったものたち。
デフォルト設定ファイルからのコメントアウト
カナ無変換(control+K)
【追記】2025-09-15 現在、特にこの設定があっても不便が起きていない。
{ "keys": ["ctrl+k"], "command": "run_macro_file", "args": {"file": "res://Packages/Default/Delete to Hard EOL.sublime-macro"} },
- 該当機能:カーソル位置から行末までを一気に削除
- 代用キー:cmd+fn+delete
日本語変換候補選択(Tabキー)
【追記】2025-09-15 現在、 insert_best_completion
が存在しない。
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "t", "exact": true} },
{ "keys": ["tab"], "command": "insert_best_completion", "args": {"default": "t", "exact": false},
"context":
[
{ "key": "setting.tab_completion", "operator": "equal", "operand": true },
{ "key": "preceding_text", "operator": "not_regex_match", "operand": ".*\b[0-9]+$", "match_all": true },
]
}
- 該当機能:コード補完
- 代用キー:なし
- 補完候補の選択は 上下キー または control+space で可能。
- 後者はOS側でSpotlight検索に割当てている可能性あり。
日本語テキストの検索・置換
【追記】2025-09-15 現在、特にこの設定があっても不便が起きていない。
- 参考記事:Sublime Textの検索窓に日本語を入力する方法 · GitHub
- 日本語の入力確定(=return)より優先されてしまう挙動箇所をコメントアウトする。
- returnキーで次の検索結果に飛べないのは cmd+G で代用可能。
// Find panel key bindings
{ "keys": ["enter"], "command": "find_next", "context":
[{"key": "panel", "operand": "find"}, {"key": "panel_has_focus"}]
},
// Replace panel key bindings
{ "keys": ["enter"], "command": "find_next", "context":
[{"key": "panel", "operand": "replace"}, {"key": "panel_has_focus"}]
},
// Incremental find panel key bindings
{ "keys": ["enter"], "command": "hide_panel", "context":
[{"key": "panel", "operand": "incremental_find"}, {"key": "panel_has_focus"}]
},