vscodeでemacsのC-sでの検索の体験を再現したい
以下のような形で動かしたい
ctrl + s => find
(findのダイアログが開いた状態で) ctrl + s => find next
(findのダイアログが開いた状態で) ctrl + r => find previous
これ入れるだけで解決した (インストールし忘れてた)
keyboard shortcuts
そもそもkeyboard shortcutsの設定は
- 設定ファイル
- 設定方法
設定方法
[!TIP]
特徴的なflavorのキーマップを用意する拡張はkey map extensionという名前のよう
debug
ctrl + shift + p で Developer: Toggle Keyboard Shortcuts Troubleshooting
を開くとなんか教えてくれそう
設定ファイル
keybindings.jsonっぽい
mac: ~/Library/Application Support/Code/User/keybindings.json
// Place your key bindings in this file to override the defaults
[
{
"key": "ctrl+x shift+l",
"command": "emacs-mcx.transformToLowercase",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+x ctrl+l",
"command": "-emacs-mcx.transformToLowercase",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+x ctrl+l",
"command": "workbench.action.gotoLine"
},
{
"key": "ctrl+g",
"command": "-workbench.action.gotoLine"
},
{
"key": "ctrl+x shift+w",
"command": "workbench.action.quickSwitchWindow"
},
{
"key": "ctrl+oem_4 r",
"command": "editor.action.startFindReplaceAction",
"when": "editorFocus && !config.emacs-mcx.useMetaPrefixMacCmd"
},
{
"key": "ctrl+oem_4 r",
"command": "editor.action.startFindReplaceAction",
"when": "editorFocus || editorIsOpen"
},
{
"key": "ctrl+h",
"command": "-editor.action.startFindReplaceAction",
"when": "editorFocus || editorIsOpen"
},
{
"key": "ctrl+oem_4 r",
"command": "editor.action.startFindReplaceAction",
"when": "config.emacs-mcx.useMetaPrefixMacCmd && editorFocus"
},
{
"key": "ctrl+c d",
"command": "deleteInsideWord"
},
{
"key": "ctrl+c ctrl+p",
"command": "workbench.action.previousEditor"
},
{
"key": "ctrl+c ctrl+n",
"command": "workbench.action.nextEditor"
},
{
"key": "ctrl+c e",
"command": "editor.action.insertSnippet",
"when": "editorTextFocus",
"args": {
"snippet": "\"${TM_SELECTED_TEXT}\""
}
},
{
"key": "ctrl+c q",
"command": "editor.action.commentLine",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+oem_4 shift+oem_comma",
"command": "cursorTop",
"when": "textInputFocus"
},
{
"key": "ctrl+oem_4 shift+oem_period",
"command": "cursorBottom",
"when": "textInputFocus"
}
]
whenってどんな種類があるんだろう?この辺?
例えばこんな感じ
Context name | True when |
---|---|
Editor contexts | |
editorFocus | An editor has focus, either the text or a widget. |
editorTextFocus | The text in an editor has focus (cursor is blinking). |
textInputFocus | Any editor has focus (regular editor, debug REPL, etc.). |
inputFocus | Any text input area has focus (editors or text boxes). |
context keyの調べ方
おそらく、Developer: Inspect Context Keys
で調べられる。
Developper: Toggle Developer Tools
をする必要がある
クリックするとなんか手に入る
whenで利用できるoperator
Operator | Symbol | Example |
---|---|---|
Equality | == | ['editorLangId == typescript'] |
Inequality | != | ['resourceExtname != .js'] |
Or | ||
And | && | ['textInputFocus && !editorReadonly'] |
Matches | =~ | ['resourceScheme =~ /^untitled$ |
remove keybindingは-<name>
みたいな感じで登録されるみたい。
{
"key": "ctrl+h",
"command": "-emacs-mcx.deleteBackwardChar",
"when": "editorTextFocus && !editorReadonly"
},
{
"key": "ctrl+h",
"command": "-deleteLeft",
"when": "textInputFocus"
}
💭 個人的にはCtrl+hでの削除を使わないし、いっそのことコマンドパレットの起動をこれにしちゃいたい。
keybindings.json がこの辺で設定されている。コマンドは自作なのかな?
package.jsonでcommandが定義されてる
このへんでコマンドが登録されてる
runCommandはこれ
emulatorの持つcommand registryへの登録はこれ
コマンドの実装はこれ
editor.action.nextMatchFindAction が使われる?
vscode側のコード
これでCtrl + s後のctrl + sで再検索が効くようになるのかな
実際 toggle keyboard shortcuts をtraceしてみると
2024-05-30 21:31:35.542 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:35.542 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:35.543 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:35.543 [info] [KeybindingService]: \ From 3 keybinding entries, matched emacs-mcx.isearchForward, when: !findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:35.543 [info] [KeybindingService]: + Invoking command emacs-mcx.isearchForward.
2024-05-30 21:31:35.771 [info] [KeybindingService]: + Ignoring single modifier ctrl due to it being pressed together with other keys.
2024-05-30 21:31:36.361 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: ControlRight, keyCode: 17, key: Control
2024-05-30 21:31:36.361 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: ControlRight, keyCode: 5 ('Ctrl')
2024-05-30 21:31:36.364 [info] [KeybindingService]: \ Keyboard event cannot be dispatched in keydown phase.
2024-05-30 21:31:37.161 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:37.162 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:37.162 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:37.162 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:37.163 [info] [KeybindingService]: + Invoking command editor.action.nextMatchFindAction.
2024-05-30 21:31:37.591 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:37.592 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:37.592 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:37.592 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.
2024-05-30 21:31:37.593 [info] [KeybindingService]: + Invoking command editor.action.nextMatchFindAction.
2024-05-30 21:31:38.017 [info] [KeybindingService]: / Received keydown event - modifiers: [ctrl], code: KeyS, keyCode: 83, key: s
2024-05-30 21:31:38.017 [info] [KeybindingService]: | Converted keydown event - modifiers: [ctrl], code: KeyS, keyCode: 49 ('S')
2024-05-30 21:31:38.018 [info] [KeybindingService]: | Resolving ctrl+[KeyS]
2024-05-30 21:31:38.019 [info] [KeybindingService]: \ From 3 keybinding entries, matched editor.action.nextMatchFindAction, when: findInputFocussed, source: user extension tuttieee.emacs-mcx.