1136

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?

congusbongus
  • 13,359
  • 7
  • 71
  • 99
Dofs
  • 17,737
  • 28
  • 75
  • 123

21 Answers21

1757

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.

wjandrea
  • 28,235
  • 9
  • 60
  • 81
Mike
  • 18,257
  • 1
  • 18
  • 12
  • Ctrl+e only seems to show the first-found file. How to find multiple files with the same name under various folders? – SamDevx May 25 '16 at 06:28
  • 1
    That's the responsiveness of the vscode. When you stop typing, it will perform a search across the files. By default, it shows recent files first and does actual search later. P.S. default is both Ctrl+P and Ctrl+E now (key binding of workbench.action.quickOpen). – Mike May 25 '16 at 14:43
  • 24
    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. – Sonic Soul Jun 07 '16 at 23:38
  • 26
    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. – Julian Jun 13 '16 at 17:23
  • 13
    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 – Tiago Dec 22 '16 at 12:16
  • 28
    This answer looks obsolete or incorrect. Another answer is correctly stating that the right combination is `cmd` + `p`. – Ivan Yurchenko Jan 24 '17 at 12:12
  • Can't you just override the ignored search files in `.vscode/settings.json`? – jscul Mar 10 '18 at 21:08
  • 15
    This search only recent files, not all files – Hrvoje Golcic Jun 12 '18 at 09:20
  • @HrvojeGolcic not only, when you start typing it searches both, it has a small delay because of async operations – Mike Jun 12 '18 at 09:40
  • @Mike actually you're right I see now. But for some reason it just don't want to search for bootstrap lib files that I have in 'node_modules' folder even though it finds other things in 'node_modules' folder. I don't get it – Hrvoje Golcic Jun 12 '18 at 10:10
  • you may try https://stackoverflow.com/questions/33258543/how-can-i-exclude-a-directory-from-visual-studio-code-explore-tab#answer-33277809 – Mike Jun 14 '18 at 15:56
  • 1
    only search recent files (Mac OSX) – sakhunzai Feb 12 '19 at 08:46
  • What about file name patterns like "*.map"? – Jens Mander May 22 '19 at 11:39
  • Note, this is for the default VSCode shortcut keys. Thank you Mike – Jovylle Oct 05 '21 at 04:13
  • @sakhunzai Ensure your files are not ignored. Ain't they in `.ignore` or `.gitignore` directories? Was my case precisely. Checkout this one: https://stackoverflow.com/questions/55949132/vscode-how-to-get-file-search-not-content-to-include-git-ignored-files – Onkeltem Jan 24 '22 at 05:48
  • I sometimes wonder, does any thought go into these default assignments _at all_? Obviously `Cmd-f` is already associated with `find text` but I wonder what mnemonic the designers were thinking when they associated `Cmd-p` with `Go to file`? Eclipse for example has `Cmd-Shift-R` for similar `Open Resource` which is easier to remember... Of course remapping is possible but there could be conflicts. – Ed Randall Feb 10 '22 at 11:34
  • The ctrl+f inside of the tree is entirely useless as it only searches expanded files. In big projects you will have to use ctrl+p or go back to your file explorer and search there. – MattyMatt Apr 20 '23 at 16:15
  • @MattyMatt That solution was plagiarized from [A. Morel](/a/61460276/4518341)'s answer and has been removed. You can move your comment there if you'd like. – wjandrea Aug 21 '23 at 15:00
101

Since the 1.70.0 release in July 2022, you can find and filter in tree views such as the Find Explorer. You can press Ctrl+F inside trees to pop up the Find control.

Before the 1.70.0 release

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")

enter image description here

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 !

A. Morel
  • 9,210
  • 4
  • 56
  • 45
  • 11
    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 – Jacques Sep 14 '20 at 09:24
  • This stopped working for me a while ago and I don't know why. Wasn't able to find any option to en- or disable it. Have I overlooked anything? – audioslave Jan 29 '21 at 12:07
  • @audioslave I currently have version 1.52.1 of VS Code and it works fine. – A. Morel Jan 29 '21 at 16:59
  • 8
    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. – Stephen Teodori Feb 05 '21 at 15:43
  • @StephenTeodori I think it's a bug. When I went to change the "Collapse Results" setting, it worked again. – A. Morel Feb 05 '21 at 19:29
  • This is almost helpful. But VSCode doesn't allow you to expand all folders so it's a bit useless to find multiple files in a large project. – Phill Apr 21 '21 at 08:18
  • can you customize this color? – relik May 13 '21 at 20:24
  • Issue with symlinks https://github.com/microsoft/vscode/issues/124341 – irvnriir May 21 '21 at 12:22
  • While this feature still exists, I think it's use is not intuitive and it certainly has its limits. For example, it appears when a folder is not expanded its contents will not be considered by the filter. A better option appears to `Ctrl` + `p` Windows or the equivalent on other OS'es. – Manfred Jun 12 '21 at 12:17
  • I find this feature totally useless in its current form. Hopefully this will be improved, visual studio solution explorer does this much better. Ctrl-P is a clunky alternative when you want to see more than one file at once in situ – Brett Jul 25 '21 at 11:04
  • 1
    I've created this to see if it could be improved https://github.com/microsoft/vscode/issues/129340 – Brett Jul 25 '21 at 11:37
  • 3
    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. – Kalnode Jan 26 '22 at 15:53
  • 1
    @MarsAndBack Indeed, I fully agree! Here is a Github issue for improving this feature, vote for it if you want an improvement: https://github.com/microsoft/vscode/issues/70646 – Tobias Feb 22 '22 at 09:35
  • it does not work https://i.imgur.com/aVWvBSg.png – marko kraljevic Jul 16 '22 at 06:48
  • I need it and somehow it no more works in the latest version 1.70.2 – Mohamed Allal Aug 23 '22 at 12:58
  • 2
    This is deprecated. No more work. Check this answer for the new way and the details https://stackoverflow.com/a/73459511/7668448. Focus on tree and `CMD/CTRL + F ` – Mohamed Allal Aug 23 '22 at 13:20
  • I am using version 1.73. The filtering feature does not work for files which are in folders which are not expanded, and is therefore not usable as a "search" feature, which is what this stackoverflow question is about. – Étienne Nov 09 '22 at 10:29
  • Thank you for the edit; Your post was part of my workflow and didnt work anymore recently. Good old google brought me back to your answer and my workflow is now updated. – Alex Jan 02 '23 at 13:52
  • this only when is the Explorer files are expanded – Normal Jan 23 '23 at 20:32
  • if you have nested folders this won't find the search but you must expand the Explorer tree – Normal Jan 23 '23 at 20:32
86

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

Tiago
  • 2,871
  • 4
  • 23
  • 39
nikk wong
  • 8,059
  • 6
  • 51
  • 68
  • 1
    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 https://code.visualstudio.com/docs/editor/codebasics – bitsand Dec 13 '16 at 17:15
  • This should be the accepted answer, commands have changed in more recent versions. – Tyguy7 Jul 24 '17 at 22:19
  • 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 Aug 15 '19 at 09:36
  • @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. – bronson Jan 23 '20 at 23:04
  • Or, @Mark, a much better answer: https://stackoverflow.com/questions/38713405/open-files-always-in-a-new-tab – bronson Jan 24 '20 at 00:22
  • To filter files within the tree it's better to use the new filtering method as shown here https://stackoverflow.com/a/73459511/7668448. focus on tree and `CMD/CTRL + F` – Mohamed Allal Aug 23 '22 at 13:22
49

Method 1

  1. Go → Go to File (shortcut: Ctrl + p).

  2. Search your file:

    video with steps of method 1

Method 2

  1. View → command palette (shortcut: Ctrl + Shift + p).

  2. Type "Go to file"

  3. Search your file:

    video with steps of method 2

double-beep
  • 5,031
  • 17
  • 33
  • 41
lava
  • 6,020
  • 2
  • 31
  • 28
36

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. :)

LightCC
  • 9,804
  • 5
  • 52
  • 92
GorvGoyl
  • 42,508
  • 29
  • 229
  • 225
28

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)

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
JLF
  • 2,280
  • 4
  • 28
  • 45
  • 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 ? – delphirules Jul 18 '19 at 16:19
  • 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 – JLF Jul 18 '19 at 21:06
  • oh finally i find that keybindings. – Robin Jun 05 '20 at 12:43
24

Also works in ubuntu with Ctrl+E

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
19

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

ochs.tobi
  • 3,214
  • 7
  • 31
  • 52
16

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.

shaheen g
  • 691
  • 6
  • 6
14

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

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

enter image description here

enter image description here

Siddarth Kanted
  • 5,738
  • 1
  • 29
  • 20
14

For filtering in the tree on keyboard typing. The feature is deprecated. No more work.

No more of this old red inflexible box:

enter image description here

The replacement is way better and more interesting:

Actually not really. It could have been. The new way only filters on expanded folders only. And that's a shame. Check the last session for where the development is at. And for the options we are left with.

https://code.visualstudio.com/updates/v1_70#_tree-find-control

CMD + F (mac) or CTRL + F (else) [while focused]

vscode tree filtering new implementation

enter image description here

No settings are needed. It just works. And more elegantly (except for the problem of only filtering searching through the visible expanded directories).

And for the default mode. highlight or filter. You can change that with:

"workbench.list.defaultFindMode": "highlight"
"workbench.list.defaultFindMode": "filter"

enter image description here

Only the open folders and visible elements Problem and what are we at?

It's great to know about this feature. But then you'll soon encounter the limitation it has at the moment.

Filtering only through open directories. It can help great. But then we want to filter through all. And when the project is big. That becomes totally unusable.

Issues: 1, 2, 3

We can see it's added to the backlog here: https://github.com/microsoft/vscode/issues/116286

duplicates: 1

You may think:

Expand all

Ok what about expanding all. Then using this. ===> That would work great => But => There is no such a feature of expanding all now.

Issues: 1, 2, duplicates: 1

Some configuration

At the moment no configuration does help!

"workbench.list.keyboardNavigation": "filter"

doesn't and many others. I tried them all. For the moment!

Extension that do that probably using web view

None exists. And to be implemented one needs to figure out the indexation used by vscode. Or implement its own indexation and then fuzzy search through using indexes. Otherwise something more simple that works for no big directories. Can be built fast. [I don't have time to do it myself. Especially that this would be resolved sometime in the future and we still can work with CTRL|CMD + P]

So that to clear for you the thoughts that you may get. And save you time.

Resume

So shortly we may see the feature of filtering all in a future version of vscode as it was added to the backlog. Right now we will be waiting. And maybe long enough.

Expand all seems not to be coming at any time or any time soon.

So what now. Left with nothing? Here a WORKAROUND

The now is => use CTRL|CMD + F on visible things. or on folders. By manually expanding them.

Or use CTRL|CMD + P without closing it. By following the next rules:

enter image description here

  • To open multiple files in the same editor. Navigate up and down and for each file use Right Arrow.
  • When they open they will be opened beside each other. You can use CMD|CTRL + ALT + LEFT | RIGHT to navigate between tabs left and right. Faster and better with the keyboard. The last open is the one you'll be at when you close the pallet.
  • To open a file in a new split editor use ALT + RIGHT ARROW.

Ref: 1

UPDATE 26/07/2023 (vscode 1.80.1):

  • Nothing useful. Except for some new features. But filtering is the same.

As of now the search and filter in the file explorer are as follows:

enter image description here

  • Fuzzy match is added
  • The filter is always there

Here a preview of the fuzzy search

enter image description here

Otherwise here are some notes on the current state:

  • When you use the filtering, it will filter only what is visible
    • (No change)
  • Always no option for expanding all.
    • (no change)
  • If you click on a folder and the folder has no sub dir, if it contains something it would show, if not it would disappear.
    • Simply because when you expand, all become visible, then filtering applies.
  • Search navigation added
    • If you search for something. And results are found. You can navigate by the Up and down keys.
    • That was demonstrated on the fuzzy search gif example above.

Here are some previews that show how, if the project structure is small. You still can find the filtering on the explorer good for many use cases.

  • Navigation

enter image description here

  • Filtering

enter image description here

 - Even if not found, the search in visible only. So you have to check folders

enter image description here

 - You can still navigate and filter in such a manner.
 - It can still be useful. Depending on your case and the size of the project.
 - Specially if you needed to go through project structure.
 - Otherwise, the workaround by the command pallet is our best solid tool .

enter image description here

 - In big projects. Or directory it's totally useless.
 - (no one wants to play super Mario).

enter image description here

 - Once you go through all
     - Disable the filtering and u get all expanded
     - activate filter again, and filtering go right (already all is expanded)
Mohamed Allal
  • 17,920
  • 5
  • 94
  • 97
  • as of October 2022 this is the only correct answer. Thanks! – Nick Oct 23 '22 at 12:44
  • 2
    no it doesn't work. It will filter files that are in the expanded folders, but it will not search files in your workspace. – Anthony Brenelière Oct 27 '22 at 20:29
  • 1
    This is totally unusable for big folder trees, since it does not search for files which are not in expanded folders. – Étienne Nov 17 '22 at 13:08
  • I do agree. At first, when I wrote I didn't pay attention. Then I was busy with life to update the answer. I just did. So that people don't fall for that deception. you can check the update. Unfortunately, we are bound to wait. There isn't a way now. I included the logical workaround that we can go for at the moment. – Mohamed Allal Nov 17 '22 at 14:39
12

I'm using VSCode 1.12.1

OSX press : Cmd + p
Giang
  • 2,384
  • 2
  • 25
  • 26
12

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

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

enter image description here

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
Xin
  • 33,823
  • 14
  • 84
  • 85
8

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

MonirRouissi
  • 549
  • 8
  • 7
6

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

Misha Akopov
  • 12,241
  • 27
  • 68
  • 82
Vinod Kumar
  • 562
  • 5
  • 12
3

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.

Ying n Yang
  • 79
  • 1
  • 3
2

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

Peter Koopman
  • 311
  • 5
  • 10
1

With VSCode 1.75 (Jan 2023), you will have a new file filter option: a 'Fuzzy Match' toggle.

That comes from issue 116286: Tree: Support continuous find

In a list of files I can filter them by start typing the name of the file. It is a super useful feature when you have hundreds+ files.
My issue is that the filter is trying to find the letters in the whole file name.
Here is an example search for word "file":

this-is-**file**-i-looked-for.jpeg (I expect this to be returned)
**f**or-th**i**s-**l**.jp**e**g    (This should not be returned, it is only a random match)

Would it be possible to add there extra settings to only returns full strings matches? Or is there some setting already buried somewhere?

Solution: adding a 'Fuzzy Match' toggle button to the tree find widget.

https://user-images.githubusercontent.com/6726799/199584855-b57f8efe-0efa-4e97-8523-6fb26d61a951.gif

New options:

  • defaultFindMatchTypeSettingKey.fuzzy: Use fuzzy matching when searching.
  • defaultFindMatchTypeSettingKey.contiguous': Use contiguous matching when searching.
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

Ok, coming from a big Tmux + Vim user that often wants VSCode to "bend to my will", this is how I looked at it.

  • CMD+P is sub-optimal when you have a large workspace. The alternative here is to "use less folders in the VSCode workspace" (since VSCode cries and buckles it's knees trying to index things as they are even added) / "use more workspaces". If you use less folders and files, then CMD+P fuzzy-search works fine
  • CMD+F is find IN files, not FOR files. If that's your thing, sure, go for it, but I want to find a file deep in a project quickly and open it up, not drill down 10 levels like a cave man.

What I found works best, is this:

  • Click on the folder I am currently working on code changes for on the left side > Open integrated termainl
  • Issue `find src/ -name "something*.ts"
  • CMD + Mouse Click the file and voila! Pops into the editor.

The fact I can't right click or CMD+SHIFT+F can't just show me files when it even prepends the path for "files to include" and deep searches the files anyway.... is bonkers to me. The find mechanism with CMD+SHIFT+ already has the capability, just show me the FILES, not what's IN the files as an option. 90% of the work is already there.

So TL:DR, if you want to find a file quickly in a folder, just open a terminal, find it, and CMD + <Mouse Click>.

0

I ended up installing the extension File Name Search. It displays in the side navigation bar all files that match a name part, so I can open them one by one to check them or process them.

  • Ctrl + p: we have to repeat the search for each file
  • Ctrl + f in the explorer: it does not search, it just filters files in epanded folders

Here is a demo of a search in explorer followed by a search in the Filename search extension:

enter image description here

Anthony Brenelière
  • 60,646
  • 14
  • 46
  • 58
0

tl;dr

Use right arrow key!
Opens files in tabs, without closing current search!!!


Full Steps

⌘+p
⬆️ / ⬇️
➡️

In-depth / Explanation

1 Open command palette

cmd + p

2 Search

Type name of file you're searching for

3 Up/Down Highlight

Use up/down arrows to highlight file you want to open

4 Right Arrow

Use right arrow key to open highlighted file in new tab

Riveascore
  • 1,724
  • 4
  • 26
  • 46