Automatically Open the Current Directory in VS Code From Terminal

Automatically Open the Current Directory in VS Code From Terminal

Last year, I was blown away by some Terminal commands that I learned. My favorite one is open . to open a Finder window for whichever directory you are currently in.

At one point I had a similar command to instantly open a folder in VS Code (Visual Studio Code), but deleted it after I switched from VS Code to Atom. I’ve since switched back to VS Code and after begrudgingly dragging folders into VS Code to open them, I decided to figure out how to enable that command.

Luckily, it’s takes a few steps to activate.

  • With VS Code running, enter Command + Shift + P to open the Command Palette (or View > Command Palette from the menu bar)
  • A search bar will open up. Search for “Shell” or “Shell Command” and you should see one named Shell Command: install "code" command in PATH.
  • Select it and a confirmation Shell command "code" successfully installed in PATH. should pop up (for me the pop up appeared in the lower, righthand corner).
  • If you already have a Terminal session running, quit or restart it.
  • When you are in the directory of the files you want to open in VS Code, type code . (that is the word “code” followed by a space, then a period) and the folder will automatically open in VS code.

One response to “Automatically Open the Current Directory in VS Code From Terminal”

  1. Just learning and relying on VSCode as my default, did a search on opening from command line and yours was the top hit. Worked like a charm!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.