Reputation: 9327
After I search through files in the project directory with Command-Shift-f, the files that are opened are have the search string highlighted. The only way to unhighlight them seems to be to clear the search results. But typing "Esc" doesn't do that. I have to click the top-right corner "Clear Search Results" button. Is there a keyboard shortcut for that?
Upvotes: 12
Views: 7555
Reputation: 9897
If anyone is interested how one can clear search history from CLI, this worked for me on macOS:
rm -rf ~/Library/Application\ Support/Code/User/workspaceStorage/
Upvotes: 0
Reputation: 61462
This isn't precisely what the OP asked for but it is closely related. The idea is to fully undo the effects of pressing the shortcut for "Search: Find in Files", which means activate Explorer and focus the text editor.
{
"key": "shift+escape",
"command": "extension.multiCommand.execute",
"args": {
"sequence": [
"workbench.view.explorer",
"workbench.action.focusActiveEditorGroup"
]
},
"when": "searchViewletVisible"
}
This requires the multi-command extension.
Upvotes: 1
Reputation: 2411
A long shortcut :-) is:
Select find-in-files string: ⇧⌘F
clear the string: ⌫
clear the results: ↵
close the panel: ⌘J
(Mac ⌘ → Windows Ctrl).
Upvotes: 0
Reputation: 16099
Update:
Now you can add keybindings for these commands. Example:
{
"key": "cmd+escape",
"command": "search.action.clearSearchResults",
"when": "editorTextFocus"
}
The best way to find these commands is by searching in the Keybindings editor. The others are search.action.refreshSearchResults
and search.action.collapseSearchResults
.
Original answer:
Not yet, but there is an open feature request to allow it: https://github.com/Microsoft/vscode/issues/23558
Upvotes: 9
Reputation: 126407
No, there's no default keyboard shortcut for "Clear Search Results."
⇧⌘E (among others) unhighlights search matches in the editor but doesn't clear search results.
To make Esc clear search results, add the key binding rule below to your keyboard shortcuts file.
{
"key": "escape",
"command": "search.action.clearSearchResults",
"when": "hasSearchResult"
}
Instuctions: Key Bindings for Visual Studio Code: Advanced Customization
Side effect: Since this rule conflicts with Esc for closeFindWidget
, you must use ⇧Esc to close the find widget when you also have search results. (There may be other conflicts. I don't know.)
Note: This command works when the editor has focus, but clearing search results (either with the mouse or keyboard) moves the focus to the search input box. You can use ⌘1 to move the focus back to the editor.
Upvotes: 3
Reputation: 1421
Seems they added a Search: Clear
command (which you will need to set your own shortcut for), but it only clears entries in the side panel, and only if you have actually run the search.
My workaround for this for a simple search is Ctrl+F Backspace Esc. That is, press hotkeys for a new search, which automatically highlights the old value, then delete that search and escape.
Upvotes: 1