I am trying to define a shortcut to find the word under the cursor in all files in VSCode with Vim extension enabled.
Usually I would do:
- yiw (to copy the word under the cursor)
- Ctrl+Shift+F (to open the find in all files panel)
- Ctrl+V (to paste the copied word)
The idea would be to execute the steps by pressing my leader key (space) and F, but I could live with a Ctrl+F10 or similar solution.
What's the best approach here? Could this be done just with Vim?
I tried stuff like:
"vim.normalModeKeyBindings": [{
"before": ["<leader>", "f"],
"after": [ "y", "i", "w", "workbench.action.findInFiles", "<C-v>" ]
}]
but it doesn't accept commands like that, only keystrokes (?).
After some initial tests, I'm guessing I need the Multi-Command Extension to be able to replicate all the steps (I'm not sure, though).
I also tried:
"key": "ctrl+f10",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"editor.action.addSelectionToNextFindMatch", // trying to select the word here, it's incomplete.
"workbench.action.findInFiles",
"workbench.action.paste"
]
}
but it doesn't respond, maybe Vim mode blocks it in some way? Keybindings.json doesn't have a ctrl+f10 keybinding, so it should be free.
EDIT: Just for clarification, I finally added this to "vim.normalModeKeyBindings" in settings.json to make it work:
"before": ["<leader>", "f"],
"commands": [
"editor.action.addSelectionToNextFindMatch",
{
"command": "workbench.action.findInFiles",
"args": {
"query": "${selectedText}",
"triggerSearch": true
// "isRegex": true,
// "replaceString": "******",
}
}
],
Thanks to Mark's reply.
You can do this easier than you think. Try this keybinding:
or, to automate the selection:
runCommandsis a built-in vscode command that can run multiple commands, so no need formultiCommandhere