How to open Visual Studio code from Command Line

Visual Studio code (VS code) is an open source code editor developed by Microsoft and operating on Windows, Linux and Mac OS. It is written in TypeScript, JavaScript and CSS, so it offers deep built-in support for Node.js and also supports many languages like C++, Java, TypeScript, JavaScript, JSON and more, what makes Visual Studio code one of the best free Code Editors in 2020.

Visual Studio code Features

Visual Studio code is known for its :

  • Code refactoring & debugging
  • Easy extensibility and customizability
  • Variety of plugins and themes
  • Integrated Terminal (Command Line Interface)

You can download VS code for free here: https://code.visualstudio.com/

devdotcode-VScode

Open Visual Studio code from your Command Line Interface

To follow the rest of this article you need to have Command Line application setup (you can check here how to setup Command Line ) and Visual Studio code installed.

Windows users

When you install VS code in your computer, it is added automatically to the environment path. As a result you can open VS code from the the command line by just typing code then press enter, this will open an instance of VS code in the current directory and wright where you left in the last session.

 code

To start a brand new project in VS code you can use the command code with -n option for new.

 code -n

To open Vs code in the current directory you run code command followed by a dot.

 code .

If you want to open a specific file in the current directory (lets say you want to open package.json) you can use this command:

 code --goto package.json

to get more options run:

 code --help

Mac OS users

For the mac OS users, you need first to add VS code to the environment path, for that follow this steps:

  • First, in your Terminal open file .bash_profile or .zshrc
 open ~/.bash_profile

OR

 open ~/.zshrc
  • Then add to it this line of code
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
bash_profile
.bash_profile after adding the code
  • Finally, save (command + S) .bash_profile file, and run :
 code .

this will open an instance of VS code in the current directory. Now you can use the same commands above.

To start a brand new project in VS code you can use the command code with -n option for new.

 code -n

If you want to open a specific file in the current directory (lets say you want to open package.json) you can use this command:

 code --goto package.json

to get more options run:

 code --help
Translate »