🔧 設定内容の全体像
{
// Git Rebase Message
{
"key": "ctrl+enter",
"command": "runCommands",
"args": {
"commands": [
"workbench.action.files.save",
"workbench.action.closeActiveEditor"
]
},
"when": "editorTextFocus && !editorReadonly && editorLangId == 'git-rebase'"
},
}技術スペック
| 項目 | 内容 |
|---|---|
| 目的 | Git rebase 用メッセージ編集画面で,Ctrl+Enter により「保存+エディタを閉じる」操作を自動化する |
| キー割り当て | ctrl+enter |
| コマンド | runCommands(複数コマンドの連続実行) |
| 実行コマンド列 | 1. workbench.action.files.save(ファイル保存)2. workbench.action.closeActiveEditor(エディタを閉じる) |
| 動作条件 | editorTextFocus && !editorReadonly && editorLangId == 'git-rebase'= 編集可能な Git rebase メッセージ編集中のみ有効 |
| 適用範囲 | 言語モードが git-rebase のファイル(通常 .git/rebase-merge/git-rebase-todo) |
設定詳細
when条件
| 条件 | 意味 |
|---|---|
editorTextFocus |
テキストエディタにフォーカスがある(=テキスト入力できる状態) |
!editorReadonly |
エディタが読み取り専用でない(=編集可能) |
editorLangId == 'git-rebase' |
開いているファイルの言語モードが "git-rebase"(=Git rebase メッセージ編集画面) |
Appendix: VSCodeでのmultiple Commandsショートカットの設定
VScodeでは "command": "runCommands", を設定することで,複数のコマンドを順番に実行するように設定できます.
Example 1 (引数なしで複数のコマンドを実行)
- 現在の行を下にコピー
- 現在の行をコメント化
- コピーした行にカーソルを移動
という手順を実行するショートカットの場合,以下のように keybindings.json を設定します
Example 2 (引数付コマンドの実行)
{
"key": "ctrl+meta+l",
"command": "runCommands",
"args": {
"commands": [
{
"command": "workbench.action.terminal.focus"
},
{
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "git lastdiff ${file}\u000D"
}
}
]
},
"when": "editorFocus"
},| 項目 | 説明 |
|---|---|
"key": "ctrl+meta+l" |
このショートカットを押したときに動作 |
workbench.action.terminal.focus |
ターミナルにフォーカスを移す |
workbench.action.terminal.sendSequence |
ターミナルに文字列を送信(\u000D は Enter キー) |
"when": "editorFocus" |
エディタにフォーカスがあるときのみ有効 |
Example 3 (複数の引数を渡したい場合)
{
"key": "ctrl+shift+e",
"command": "runCommands",
"args": {
"commands": [
{
// command invoked with 2 arguments: vscode.executeCommand("myCommand", "arg1", "arg2")
"command": "myCommand",
"args": ["arg1", "arg2"]
}
]
}
}