How to call VS Code Editor from the command line

This question says it all.

How can I call the VS Code editor from

  • windows cmd
  • linux and mac terminal

eg. for notepad ++ I write

> start notepad++ test.txt

By the way, the editor is awesome (cross-platform)! Thanks, Put it on!

You can download it from microsoft.

+95
command-line terminal visual-studio text-editor visual-studio-code
Apr 30 '15 at 9:11
source share
14 answers

Use the code/path/to/file/or/directory/you/want/to/open code/path/to/file/or/directory/you/want/to/open to open your file in VS Code.

On Windows and Linux, the code command should be installed automatically. On macOS, you must install it manually:

Launch VS Code. Now open the command palette (F1) and enter shell command to find the Shell Command: Install 'code' command in PATH command . Restart your terminal.

+195
Oct 19 '16 at 10:43
source share

According to the docs :

Mac OS X

  1. Download Visual Studio Code for Mac OS X.
  2. Double-click VSCode-osx.zip to expand the contents.
  3. Drag and drop Visual Studio Code.app into the Applications folder, making it available in the launcher.
  4. Add VS Code to the Dock by right-clicking on the icon and choosing "Options", "Save to Dock".

Tip : If you want to run VS Code from the terminal, add the following to your ~ / .bash_profile file (~ / .zshrc if you use zsh).

 code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;} 

Now you can just enter the code. in any folder to start editing files in this folder.

Tip : You can also add it to the VS Code Insiders assembly by changing "com.microsoft.VSCodeInsiders". Also, if you do not enter the entire code of a word, just change it to c.

Linux

  1. Download Visual Studio Code for Linux.
  2. Create a new folder and extract VSCode-linux-x64.zip to this folder.
  3. Double-click the code to run Visual Studio Code.

Tip : If you want to run VS Code from the terminal, create the following link, replacing / path / to / vscode / Code with the absolute path to the executable code

 sudo ln -s /path/to/vscode/Code /usr/local/bin/code 

Now you can just enter the code. in any folder to start editing files in this folder.

+37
Nov 20 '15 at 16:22
source share

You can also run VS code from the terminal by entering code after adding it to the path:

Run the VS code. Open a command palette (โ‡งโŒ˜P) and enter shell command to find the Shell command: Set code in the PATH command. Mac Shell Commands

Restart the terminal for the new value of $PATH to take effect. You can enter code . to any folder to start editing files in this folder.

+16
May 02 '17 at 2:12
source share

VS Code must have a code editor for 2018

For Windows 10 users, much is possible, just as Mac OS users type code. ,

Find the VS VS \ bin path, for example C:\Program Files\Microsoft VS Code\bin . The bin folder contains a file called code.cmd

Follow the instructions below and be proud of your OS.

  1. Search for "Advanced System Settings" at startup.

  2. Click on environment variables

  3. In system variables, select "path" on the "Variable" tab and click "Change."

  4. Click New on the right side of the popup.

  5. Copy your path from the Explorer crumb path and paste it into the new open path in step 4, for example: - C:\Program Files\Microsoft VS Code\bin

  6. Click Ok in all open windows to confirm the changes and restart your cmd

  7. Go to your cmd and go to the working directory on the server and enter code.

C:>cd wamp64\www\react-app> code. open from VS Code on Windows.

Visual Studio Code also includes a command line (terminal) window, and you can open one or more of them using
Ctrl + ' on your keyboard.

Hope this helps someone, like many of us.

+16
Jan 31 '18 at 9:12
source share

For users of VS Code Insiders Windows ( vs code doc ):

Add the directory "C:\Program Files (x86)\Microsoft VS Code Insiders\bin" to the% PATH% environment variable.

then go to the folder that you want to open with code and type: code-insders.

+6
May 31 '17 at 17:24
source share

In the case of Linux and Mac, you want to go to the directory that you extracted the VSCode files using the "cd" command. For example:

 cd ~/Downloads/VSCode 

Then you launch the application by running ..

 ./Code 

"Code" is the name of the executable file.

If you have root access on your computer, you can configure the system to allow you to run VSCode from anywhere by associating it with / usr / bin, where links to executable files are often stored.

 sudo ln -s /path/to/VSCode/folder/Code /usr/bin/Code 

Now you can run VSCode from anywhere by typing:

 Code 
+5
Apr 30 '15 at 9:29
source share

When installing on Windows, you will be prompted to add the VS code to your PATH.

I tried to figure out how to open files using VS Code from the command line, and I already had the opportunity - I just forgot what I already added. Perhaps you have already installed it - check by going to the folder you want to open and run the code . command code . to open this folder.

+4
Apr 21 '17 at 16:48 on
source share

Sometimes setting the path from the VS Code command palette does not work

Instead, manually add your VS code to your path:

  1. Run in terminal

    sudo nano/etc/paths

  2. Go to the end of the file and enter the path you want to add
  3. Press Control-X to exit. Enter "Y" to save the modified buffer.
  4. Restart your terminal and check echo $PATH . You need something like that

~ echo $PATH/Users/shashank/.nvm/versions/node/v8.9.2/bin: /usr/local/bin: /usr/bin: /bin: /usr/sbin: /sbin: /Applications/Visual Studio Code.app/Contents/Resources/app/bin

Next time you will go to the folder of your project from the terminal

To come in:

code.

or

code/path/to/project

Source

+4
Dec 12 '17 at 16:41
source share

This works for Windows:

 CMD> start vscode://file/o:/git/libzmq/builds/msvc/vs2017/libzmq.sln 

But if the file path has spaces, usually double quotes are added to it, for example:

 CMD> start "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln" 

But this spoils the launch, which can take double quotes, so it will create a window with that name as the title and will not open the project.

 CMD> start "title" "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln" 
+1
Feb 02 '18 at 8:23
source share

For command line chapters, you can also run

sudo ln -s "/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code"/usr/local/bin/code

this will do the same as the Shell Command: Install 'code' command in PATH command in VSCode.

+1
Aug 07
source share

On Linux, if you use code. it will open VS Code in the folder in which the terminal was located. Using code. Filename.cs code. Filename.cs code. Filename.cs code. Filename.cs will open in the folder and open the specified file.

+1
Aug 14 '18 at 0:44
source share

typing "code" at the DOS command prompt worked for me

0
Jun 23 '18 at 21:05
source share

This will work. This is the name of your directory "~ / .vscode-root"

  sudo code --user-data-dir="~/.vscode-root" 
0
Nov 19 '18 at 4:15
source share

Note For Windows users only.

As many people have already suggested, ways to open code from the command line with code. team. This will only open Visual Studio Code Stable build. But if you downloaded the assembly / version of Visual Studio Code Insider (which has all the latest assemblies / functions, but an unstable version), then you need to follow the instructions below in the windows:

  • Go to Control Panel \ System and Security \ System. Click on Advanced System Settings enter image description here
  • Click on environment variables enter image description here
  • On the System Variables tab, click Modify for Path Variable enter image description here
  • Add a new path C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin (or) C:\Program Files\Microsoft VS Code Insiders\bin depending on the location where you installed the vscode insider into your file . the car. enter image description here

    Open a new command prompt and enter code-insiders. open vscode-insider build / version
0
May 19 '19 at 15:28
source share



All Articles