'VS Code - How to open a file by its full path in the command palette?

I need some functions like:

VS Code -> F1 (open Command Palette) -> OpenFileFeature: /home/user/blablabla/code.py -> (Enter) -> (file opened in editor)

In this case /home/user/blablabla/code.py can be an external file (relative to my current folder open in VS Code).

Does anyone know some tricks about this?



Solution 1:[1]

In vscode you can use the command palette to open files via absolute path using the CTRL + P shortcut. Please note the difference. CTRL + P opens the file navigator whereas CTRL + SHIFT + P opens the editor command window, meaning you will see the > indicator. Additional note - you could just simply delete the > identifier as well, if using the command shortcut.

The file navigator takes absolute paths as arguments, once you filled out a file that exists it will populate in the drop down list for selection: screenshot

Notice how I do not have any workspaces open so there is no navigation history or relative file association.


Alternatively,

There is naturally the option to open via CTRL + O, where you can always enter absolute paths as well, not a command palette related answer but related option.

Solution 2:[2]

If you want to open file outside workspace in the current window:

  1. Open terminal Ctrl + `
  2. Type code [any_file_path], Enter

Solution 3:[3]

I tried the accepted answer and it did not work for me. I'm on OSX. After pressing ?+p, when I start typing absolute path of a file, it simply shows No matching results.

What worked for me was opening file from the file navigator. Go to File > Open (?+o) and locate the file in the file browser. It opens the file in same window in a tab.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 egor.xyz
Solution 3 Waseem