可视化工作室代码-如何复制搜索结果?

VisualStudio 代码是否有办法将搜索结果复制到新窗口中?

作为奖励,我真的希望能够删除文件名,只是复制行包含我的搜索结果的文本到一个新的窗口。

例如,我希望能够将下面的搜索结果复制到一个新的编辑器窗口。我不介意我需要安装一个扩展来做这件事。

enter image description here

66058 次浏览

Select all occurrences of current selection

CTRL+SHIFT+L

https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf

The following works for a single file:

  1. CTRL + F
  2. Type your search string
  3. CTRL + SHIFT + L to select all occurrences found (max. 999)
  4. ESC (or close search dialog with top-right X)
  5. CTRL + I to select whole lines
  6. CTRL + C
  7. Open new file
  8. CTRL + V

VSCode 1.23 added the ability to copy your search results, see release notes: copy search results.

The search results tree context menu includes three new options: Copy, Copy Path, and Copy All. This was a highly 👍'd request which will make it easier to share or export your search results.

The results are not very pretty or clickable when copied/pasted, so be forewarned. There is an issue tracking the "copy search results" format (see https://github.com/microsoft/vscode/issues/68877) and it is on the 2019 Roadmap (see https://github.com/Microsoft/vscode/wiki/Roadmap#workbench) so hopefully it will be improved.


Update as of v1.41 you can move your search results to a new editor and easily select all and copy there. After searching (which can work across multiple files); click the "Open in Editor" link, as shown in this demo:

search results copy in a new editor

Another advantage of the search editor is that you can get "context" around your search result. So you can get some number of lines before and after the whole line with your search term in it. And, of course, line numbers will be copied too.

search editor context demo


And you can just save Ctrl+S the search results editor itself! And cut lines from there. Or add notes. With syntax highlighting. It will ask where you want to save it, defaulting to the folder where you initiated the search. It will be named like yourFolder\yourSearchTerm.code-search.


For more info on the new search editor, see https://code.visualstudio.com/updates/v1_43#_search-editors and

This will work for a single file, assuming each line you care about begins with the search text: 1. Highlight your search string 2. CTRL + SHIFT + L to select all occurrences found 3. SHIFT + ↓ to select all of those lines 4. CTRL + C 5. Open a new file 6. CTRL + V

As of 12/2020 CTRL + SHIFT + L doesn't work (for me)

After search results are rendered, right-click onto the text file and select "Change all occurrences"(or CTRL+F2). This will automatically select the the matched text items. Then you can simply copy it.

Wrong. Per the document the correct format is to use Right Alt + Enter, the use Ctrl + C and then open a new tab and paste your results with Ctrl + V

There's now an "Open in editor" button under search inputs enter image description here