14

i'm trying to get a list of all the files with a certain name in a project i opened with VS Code.

For example, all the .gitignore files in my project. I know i can ctrl+p and type ".gitignore", but i don't want to open all the files, i want to list them, and open them one by one afterwards. Also the "open file" popup disappears as it looses focus and brings recent files to the top, altering the order every time (this makes it difficult to keep track of the files i already opened).

I've found this cool extension that only opens all the files with a certain name (it even supports wildcards). The problem is that i have tens of files, i can't open all of them together, especially if the files are not simple .gitignore files, but something bigger.

Yes i could just use my OS' file search, but that is not always possible (eg. when using a remote filesystem) or quick (it depends on how many files are in the project folder).

Toto
  • 19,304
aetonsi
  • 313

2 Answers2

20

First, select the Explorer sidebar button or open it with Ctrl + Shift + E shortcut: Explorer

Make sure it's focused by clicking on it.

Then, use on:

  • Windows: Ctrl + F, which is default keybinding before VSCode 1.89, or Ctrl + Alt + F after 1.89.
  • macOS: Cmd ⌘ + Option ⌥ + F

A search bar will appear. Enter the phrase that you want to match. Files matching it will get highlighted

You can lastly press the Filter button to only show the matched files: Filter

Destroy666
  • 12,350
1

A different approach:

  • Go to search in all files (Ctrl + Alt + F)
  • Open "files to include" section, by clicking three dots in the right bottom of search bar
  • Type the file extension to "files to include" section like this: *.gitignore, or *.csproj or *.txt etc.
  • Toggle "Use Regular Expression (Alt + R)" to open it.
  • Type ^(?<![\w\W]) to search bar, this regex matches the start of file. (https://stackoverflow.com/a/60091371/7219400)
  • This will list the initial line of all files with that extension.
Sahin
  • 133