Opening Visual Studio Code from Terminal

How to open files and directories in VS Code from the command line or Terminal.

Image

Work­ing in the Ter­mi­nal or com­mand line is eas­i­er if you can quick­ly open or access a stan­dard appli­ca­tion from it. Let’s say I was in Ter­mi­nal and want­ed to quick­ly open a project direc­to­ry in Visu­al Stu­dio Code; here’s how I’d do it:

  1. Assum­ing we already have Visu­al Stu­dio Code install, we need to install the the com­mand line tool. Open the appli­ca­tion and run ⇧⌘P to get the Com­mand Pal­lette in VS Code.

  1. Once there, type shell command and then choose Install 'code' command in PATH — this will install the com­mand line util­i­ty for VS Code in your local path.
  2. If you already have your local path defined in your ter­mi­nal envi­ron­ment, then the com­mand will just work. Nav­i­gate to a direc­to­ry in Ter­mi­nal and then run code . to open the cur­rent work­ing direc­to­ry (don’t for­get the dot (.)!

  1. This will open a new VS Code win­dow with that directory!