I want to make a keybinding that works like Ctrl+F / Cmd+F, but it starts searching at the top of the file, rather than at the current cursor location.
I haven’t found a built-in command to search from the beginning of the file, but you can easily do it by chaining the two commands “go to the top” and “find” using the runCommands
command.
As this requires passing args
to runCommands
, we can’t do this in the built-in keyboard shortcuts UI. Instead, run the command “Preferences: Open Keyboard Shortcuts (JSON)”, and then add the following entry to the array:
[
...,
{
"key": "ctrl+cmd+f",
"when": "editorTextFocus",
"command": "runCommands",
"args": {
"commands": ["actions.find", "cursorTop"]
}
}
]
Note that we’re running "actions.find"
(the “Find” command) first, and then "cursorTop"
. The reason is that the “Find” command seeds its search string from the word at the cursor position, so if we run "cursorTop"
first, it will instead seed whichever word happens to be the first in the file.