Launching Visual Studio Code from the Command Line


I use Jekyll and VSCode to author articles for this blog. One day, I got tired of searching my Mac or using my mouse to start writing. I wanted to just cd to the git repo and launch my editor just as I would with VIM. So I looked it up and decided to leave a little note for myself on how to do this.

It certainly seemed possible based on this documentation from the vscode website:

However, launching vscode using code did not seem to work on my Macbook Pro. Obviously there’s something else that has to happen. I found out you have to set this up ahead of time, at least on the Mac. Note that the documentation out there mentions adding code to my $PATH but this wasn’t the case for me. It even says this in VSCode itself, but my path remained unchanged.

In any case, it’s just a few steps:

  1. Launch VSCode:

  2. Type in CMD + SHIFT + P to search for vscommands:

  3. Type in “shell” and then select the option for “Shell Command: Install ‘Code’ Command in Path”:

  4. You’ll see a notice at the bottom that code has been successfully installed in “Path”:

  5. Launch a new terminal window. You can just type in code . to launch code with the current directory.

That’s it! The link above has more options.