VSCode: How to perform “Clear Search Results” in “Find in Files” without using the mouse?

China☆狼群 提交于 2021-01-27 04:55:36

问题


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?


回答1:


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




回答2:


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.




回答3:


A long shortcut :-) is:

Select find-in-files string: ⇧⌘F

clear the string:

clear the results:

close the panel: ⌘J

(Mac → Windows Ctrl).




回答4:


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.



来源:https://stackoverflow.com/questions/46287508/vscode-how-to-perform-clear-search-results-in-find-in-files-without-using-t

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!