ChatGPT解决这个技术问题 Extra ChatGPT

How do I search for files in Visual Studio Code?

I am used to Resharper where I can search for files, not the content, but the filename, which makes it quick to open new files.

Is this feature implemented in Visual Studio Code and is there a shortcut for it?

Can we use wildcards to search for a particular file? Example markdown files starting with Pan as Pan*.md
you can make it with Explorer Tree stackoverflow.com/a/61460710/2736742

j
javiercmh

Using Go to File... which is under the Go menu or using keyboard shortcut:

On Windows Ctrl+p or Ctrl+e

On macOS Cmd ⌘+p

On Linux Ctrl+p or Ctrl+e

Then type the file name.

Also be sure to checkout that you can set your own keybindings and that there are cheatsheets available for Windows, macOS and Linux.


this (and ctrl/cmd+p) doesn't work for excluded folders such as node_modules. it would be nice to have a way to search all files at times.
This seems to only work for the current folder. What if I want to search across the entire project? My files are rarely in the folder I'm currently in.
On OSX cmd + e searches on the current file, the correct key binding is cmd + p that brings the command palette where you can search for files and much more
This answer looks obsolete or incorrect. Another answer is correctly stating that the right combination is cmd + p.
This search only recent files, not all files
T
Tiago

On OSX, for me it's cmd ⌘ + p. cmd ⌘ + e just searches within the currently opened file.


Using VS Code Version 1.7.2 Cmd+P (Mac) or Ctrl+P (Windows) brings up the Command Palette. This gives you access to an entire set of commands including File Search. See the docs at code.visualstudio.com/docs/editor/codebasics
This should be the accepted answer, commands have changed in more recent versions.
Yes, CTRL+P allows to to type a file name in and open it. But it replaces currently opened file. How can I keep opening files just like gong through Solution Explorer and clicking files?
@Mark when the filename is in italics, it will be replaced by the next file you open. Select "Keep Open" (right-click the tab), or use "View: Keep Editor" in the command palette.
Or, @Mark, a much better answer: stackoverflow.com/questions/38713405/…
A
A. Morel

If you want to see your files in Explorer tree...

when you click anywhere in the explorer tree and start typing something on the keyboard, the search keyword appears in the top right corner of the screen : ("module.ts")

https://i.stack.imgur.com/HlM1G.png

And when you hover over the keyword with the mouse cursor, you can click on "Enable Filter on Type" to filter tree with your search !


This would be a great approach but for some reason the results are restricted to only a few items. E.g. I know I have around 30 odd files of a certain name in a monorepo - when I follow these instructions the results are limited to 6 files it seams
I'm on 1.52 and it only shows files that were visible (not in a collapsed folder) in the tree before filtering. @A.Morel try your example again but this time before you filter collapse the "dinner" folder. When you apply the filter not only will the file in that folder not appear, but the folder won't even be listed.
I've created this to see if it could be improved github.com/microsoft/vscode/issues/129340
Why after 2 years I'm only finding this now. There should be some initial UI for this and not just a key press feature.
@MarsAndBack Indeed, I fully agree! Here is a Github issue for improving this feature, vote for it if you want an improvement: github.com/microsoft/vscode/issues/70646
L
LightCC

Win: CTRL+P or CTRL+E

Mac: CMD+P or CMD+E

Don't want to remember another shortcut?

Open the Command Palette:

Menu: View -> Command Palette

Windows Shortcut: Ctrl+Shift+P

and hit backspace to delete ">" character and then begin typing to search for files via filename. :)


Deleting ">" was the key!
l
lava

Method1

Go->Go to File OR cntrl+p Search your file

https://i.stack.imgur.com/bVr49.gif

Method2

view->command palette OR cntrl+shift+p type "Go to file" Search your file

https://i.stack.imgur.com/Koyxz.gif


M
Misha Akopov

Other answers don't mention this command is named workbench.action.quickOpen.

You can use this to search the Keyboard Shortcuts menu located in Preferences.

On MacOS the default keybinding is cmd ⌘ + P.

(Coming from Sublime Text, I always change this to cmd ⌘ + T)


I accidentally deleted the CMD + P shortcut and now i can't recover it ; the d workbench.action.quickOpen does not show on my commands list... What can i do ?
You can search for the action by typing the name of the action into the Keybindings search bar in the Keybindings view. When it appears in the search results, simply click the + icon on the left side to set a keybinding again
oh finally i find that keybindings.
M
Misha Akopov

Also works in ubuntu with Ctrl+E


Works on Windows 7 as well!
Works for me on Windows 10!
o
ochs.tobi

You can also press F1 to open the Command Palette and then remove the > via Backspace. Now you can search for files, too.


This is the same as pressing Cmd + P
One difference is, this method is cross-platform
G
Giang

I'm using VSCode 1.12.1

Cmd

p


S
Siddarth Kanted

consider you have thousand of files in vs code and you want to search for a file with particular name then

Right click VS code editor. Select Command Palete In the text box type the file name

https://i.stack.imgur.com/kDoPF.png

https://i.stack.imgur.com/qWNWB.png


Need to press backspace when inside the Command Palette, before starting to type file name.
M
Misha Akopov

If you just want to search a single file name

Just Ctrl+P, then type and choose your one

If you want to open all files whose name contains a particular string

Open search panel Put any common words inside those files in 'files to include', put the search string with *, e.g. *Signaller*

https://i.stack.imgur.com/E7T0U.png


The "search panel" is called Find in Files (Ctrl+Shift+F). To access "files to include" you need to click the "..." icon (Toggle Search Details) or 4 times tab, then space and tab again.
Put any common words inside those files. That's the issue. I'd love to find every file with a certain name.
@BernhardDöbler same here!
@BernhardDöbler you can use the regex search and search for .* as a workaround if you're not looking for binary files
s
shaheen g

The problem with Ctrl+P (or Cmd+P) is that it searches your workspace while ignoring files and folders set in the .gitignore file. To change this behavior, add "search.useIgnoreFiles": false in your settings.json file under .vscode directory.

NOTE that search.exclude and files.exclude settings will override this. So, in your settings.json file, you should comment them out or set these two settings to false as well if you want to search all the files and directories in your VS Code project. An example for settings.json where search.exclude and files.exclude are commented out for searching all the files:

{
    "search.exclude": {
        //"**/Lib": true,
        //"**/Scripts": true
    },
    "files.exclude": {
        //"**/Lib": true,
        //"**/Scripts": true
    },
    "search.useIgnoreFiles": false
}

Look here for more info.


Is there any way to quickly disable excluded files for just a single search instead of modifying the settings?
M
MonirRouissi

For windows. if Ctrl+p doesn't always work use Ctrl+shift+n instead.


M
Misha Akopov

To search for specifil file types in visual studio code. Type ctrl+p and then search for something like *.py. Simple and easy


Y
Ying n Yang

If using vscodevim extension, ctrl + p won't work so I saw another answer using:

ctrl + shift + p

which opens the command palette. Hit backspace to remove the '>' and then start typing your filename.


P
Peter Koopman

Check your settings for 'Use Ignore Files' and 'Use Global Ignore Files'. If these are checked, VSCode won't search any folders listed in .gitignore or .ignore