Open a file/folder in VSCode from the Terminal

Subscribe to my newsletter and never miss my upcoming articles

A Note on the Series:

Fast Fridays 🏎 is a series where you will find fast, short and sweet tips/hacks that you may or may not be aware of. I will try to provide these (fairly) regularly on Fridays.

Have you ever been traversing through the terminal and want to open up a particular file or folder in VSCode? The long way to do this is to open up the editor, find the folder where the file is located, and then open the file. Well, there's actually a quicker way to do this with just a few configuration steps.

Configure via the Command Palette

  1. Open up Visual Studio Code
  2. Press Cmd + Shift + P (Mac) or Ctrl + Shift + P (Windows) to open up the command palette
    • Alternatively, you can do View --> Command Palette from the toolbar.
  3. Type shell command in the input and you should see the following options:

shell-command.png

4 . Select "Install 'code' command in PATH"

5 . Restart your terminal

After these steps you should now be able to run the following commands in the terminal:

  1. code <file_name> --> Opens VSCode with the specified file.
  2. code . --> Opens VSCode with the current directory you are in.

Image.gif

Resources

Comments (2)

Sandeep Panda's photo

Amazing tip and quite handy. Previously I used to do open . and then right-click => Open in VSCode.

But this one is better and quicker.

Alyssa Holland's photo

Glad it was helpful!