143

Does Visual Studio Code have any way to copy the results of a search into a new window?

As a bonus, I'd really like to be able to drop the file name and just copy the lines containing the text of my search results to a new window.

For example, I'd like to to be able to copy the results of the search below to a new editor window. I don't mind if I need to install an extension to do it.

enter image description here

6
  • can you just shift-click and select everything? Then right-click and copy? Commented Jan 31, 2017 at 15:59
  • couldn't get that to work. Tried all the options on the Selection menu as well (Select All, Expand etc.) with no luck
    – user783836
    Commented Jan 31, 2017 at 16:09
  • 1
    I don't think there's a way to do that - you should file a feature request on github for it. Commented Jan 31, 2017 at 18:24
  • Upvote features here: github.com/Microsoft/vscode/issues/8594 (copy path) and here: github.com/Microsoft/vscode/issues/17920 (copy search results) Commented Feb 1, 2018 at 18:22
  • 1
    1 point for Sublime Text. There's many benefits to simply putting the search results in an "editor".
    – tkane2000
    Commented Mar 21, 2018 at 13:18

8 Answers 8

299

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
12
  • 7
    Awesome tip. Thank you very much, really handy i nsome situations to extract relevant rows!
    – Sgedda
    Commented Nov 15, 2019 at 13:05
  • 1
    CTRL + i dont work for me , i just search with regexp ^.+(mysearch).+$ to just select al line with CTRL+SHIFT+L
    – imaginabit
    Commented Mar 9, 2020 at 11:11
  • 2
    Just a little note, I had over 5K results and was able to copy/paste them all. There was no 999 maximum. Could have been updated since the answer was given
    – stinkysGTI
    Commented Jun 19, 2020 at 22:18
  • 5
    Cmd + Shift + L on Mac
    – vargen_
    Commented Sep 3, 2020 at 7:40
  • 4
    For step 3 I needed to use Alt+Enter Commented Oct 12, 2022 at 14:35
90

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

2
  • 2
    Note that the "move your search to an editor" feature is experimental, so you have to enable the "Search: Enable Search Editor Preview" option to use it (currently using 1.42).
    – kfriend
    Commented Feb 11, 2020 at 21:21
  • 1
    And see stackoverflow.com/a/66353798/836330 for more on copying search results if you just want your search matches copied.
    – Mark
    Commented Feb 25, 2021 at 16:42
37

Select all occurrences of current selection

CTRL+SHIFT+L

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

1
  • 5
    Command + Shift + L on macOS
    – Kxrr
    Commented Apr 7, 2022 at 9:19
19

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.

1
  • 2
    this is what I was looking for! Thanks!
    – FlySoFast
    Commented Jul 8, 2021 at 8:35
6

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

5

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

2
  • 2
    Isn't that point already in the accepted answer?
    – Mark
    Commented Jun 16, 2022 at 16:32
  • @Mark yes. The accepted answer could include a clearer screenshot, like Renaud provided here. The accepted answer didn't use the language "Open in Editor" ( but I edited to include that; and reference the GIF demo in accepted answer which DOES show the clear "Open in Editor" link) Commented Aug 23, 2022 at 0:22
3

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

1

Keyboard shortcuts didn't work for me on my Mac and with the latest VSCode release.

I could copy all search results with the right-click menu

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.