573

How can I find a file by name (or path) in Visual Studio Code?

A Visual Studio shortcut I'm used to is CTRL+,, but it does not work here.

9
  • 1
    In Visual studio the shortcut is [CTRL] + ';' instead Commented Apr 28, 2017 at 4:04
  • Something similar here Commented Apr 28, 2017 at 4:06
  • 21
    It's Ctr+P. Not Ctr+, Commented Apr 3, 2020 at 11:28
  • 3
    Does this answer your question? How do I search for files in Visual Studio Code? Commented Apr 3, 2020 at 11:30
  • 1
    you can make it with Explorer Tree stackoverflow.com/a/61460276/2736742 Commented Apr 27, 2020 at 14:02

10 Answers 10

782

When you have opened a folder in a workspace you can do Ctrl+P (Cmd+P on Mac) and start typing the filename, or extension to filter the list of filenames

if you have:

  • plugin.ts
  • page.css
  • plugger.ts

You can type css and press enter and it will open the page.css. If you type .ts the list is filtered and contains two items.

Sign up to request clarification or add additional context in comments.

11 Comments

If you want to change the shortcut, look for Go to file... in File > Preferences > Keyboard Shortcuts
{ "key": "cmd+p", "command": "workbench.action.quickOpenNavigateNextInFilePicker", "when": "inFilesPicker && inQuickOpen" }
We should notice that Ctrl+P opens file in Preview mode. In order to open file in new tab, let's follow stackoverflow.com/a/43707807/190309
This does not seem to work for me, only already open files show up when searching (they can still be found after closing, but never opened files does not show).
@Zitrax is right: Ctrl+P [filename] does not work on all files in the Explorer, it only lists files that are already open -- at least when one is using a remote back-end like WSL, etc. The explorer needs a real search tool which works under all conditions.
|
54

Press Ctl+T will open a search box. Delete # symbol and enter your file name.

4 Comments

This is just a longer way around to arrive to exactly the same point as pressing directly Ctrl + P.
It's a shame this does not get more upvotes; this is solving the OP's question, whereas the answer by @Dick both finds the file and opens it, which was not the OP's request.
@MikeWilliamson This answer is exactly the same as Dick's answer, with one extra step. Ctrl+T is exactly the same as hitting Ctrl+P and entering a # character. Both this answer and Dick's answer open the file if you click on it or hit "enter"; otherwise, both just display a list of results (because they are the exact same search bar, just with differing commands.)
34

It is CMD + P (or CTRL + P) by default. However the keyboard bindings may differ according to your preferences.

To know your bindings go to the "Keyboard Shortcuts" settings and search for "Go to File"

Comments

25

I believe the action name is "workbench.action.quickOpen".

2 Comments

Useful for anyone not using the default keymap (e.g. those using the emacs keymap).
@ijoseph or the Intellij keymap
25

If you're looking for a way to have a persisted list of file names, (for example; when you need to edit files in sequance, where you know the name of the files)
There's a bit of roundabout way to do that.

Use 'Search: find in files' and search for the start of each line

It will produce a list of files that is persisted in search dialog.

  1. start 'Search: find all files' (default CTRL+SHIFT+F)
  2. In the dialog, turn on 'regex'. (the .* in the search bar.)
  3. search for: ^(?<!\n). This regex matches the first line of each file
  4. Add (part of) the filename in 'files to include'. note that this fields support wildcards.
  5. Outputs a list filenames.

Example

To find all tsconfig.json files, including variants like tsconfig.node.json
use the searchterm tsconfig*.json
find all tsconfig files
you can now click through the results to open each file.

'open in editor'

Using 'open in editor' will open the text editor with the each search result, this is list persisted as well, from here you can navigate to each file, remove entries you've processed

open-in-editor

5 Comments

Do you think they should add an icon for this next in the File Explorer palette? This seems to search in files. I want the file explorer to list all ts files. *.ts doesn't work
@1.21-gigawatts *.ts seems to work for me. Did you try a larger part of the filename to see if it matches anything at all?
As for my preference, I usually navigate to the exact file like the other answers mention. Rarely I need to apply similar edits to a bunch of files, it's then helpful to have the list persist and apply my changes in sequance. This answer comes very close. We can turn on filtering so that only the matching files are shown, what's missing is a easy way to expand/collapse all directories so that the files are actually visible.
thanks for the update. I was looking for a way to list all ts files but I didn't have a search term. It was simply show me all the ts files in the directory or project. The reason being I needed to open each TS file manually to check the structure of each class. Filtering the file panel view down to only .ts files would help organize the view.
this is not works for html files , i donot know why
6

Given that the actual configuration can be different as a result of various extensions, it doesn't seem helpful to give a specific shortcut as answer. While the default shortcut seems to be Cmd + P (on a Mac), you can find out or reconfigure it when navigating to your Settings -> Keyboard Shortcuts and search for Go to File...

Picture of keyboard shortcuts in Visual Studio Code, filtered by the command 'go to file'

In my case, the IntelliJ IDEA Keybindings Extension added the double-shift shortcut which I'm using a lot, coming from a Jetbrains IDE.

Comments

2

According to this Github page, it's now a simple Cmd+F inside the File Explorer tree on Mac (and presumably Ctrl+F on Windows). Found and highlighted all the README.md files I've been working on:

file search results in vscode file explorer pane

2

Caveat: The tree has to be fully expanded for this to work.

5 Comments

This is filtering functionality in the File Explorer tree. If your file is not already visible (in expanded directory node), it will not show up. In fact, directory containing the file you are looking for, if collapsed, will disappear when you activate the filter (click on the filter icon).
Yes, the unfortunate prerequisite is that the tree has to be fully expanded. Added that caveat.
I don't think this is a good answer for the question. This is much longer and more complicated way to find a file. It's not practical.
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
I'm upvoting this, this is the only answer that helped me after much searching (wondering why the previous "type to filter" functionality was no longer working). In a very large repo and/or certain situations, this is a necessary feature and much more useful than cmd+p. The fact that folders must be expanded is a very annoying drawback, but is not the fault of this poster. And fortunately, they are working on fixing it here: github.com/microsoft/vscode/issues/66971
2

Depending on your use case, there can be multiple things to sort.

In my case (VS Code on Ubuntu/Linux)

Vim Extension had overridden the Ctrl+P key combination, so i changed that, and things were fine.
And then it fell back onto, to its original settings of File QuickOpen.

Vim Extension taking up Ctrl + P, undo that, to get Ctrl + P for File QuickOpen.

Comments

1

It's Ctrl+Shift+O / Cmd+Shift+O on mac. You can see it if you close all tabs

1 Comment

By default Ctrl+Shift+O is "Go to symbol..." binding. Lists all symbols on the currently open page.
0

Ctrl+p did not work for linux mint 22.1 for me, any shortkeys assigned to that is ignored. Might be a shortkey consumed by the system?

Either way, by default vscode (v1.99.3) maps "go to file..." (thanks Dinei) to Ctrl+E for me. This shows the quick search bar without a preceding character (# with Ctrl+T or > with Ctrl+shift+p).

I found this question helpful to figure out if I had any shortkeys overwritten or removed myself and forgot about it.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.