How to call VS Code Editor from command line

2019-01-16 06:18发布

The question says it all.

How can I call VS Code editor from

  • windows cmd
  • linux and mac terminal

e.g. for notepad++ I write

> start notepad++ test.txt

By the way, the editor is awesome (cross-platform)! Thank you Nadella!

You can download it from microsoft

13条回答
兄弟一词,经得起流年.
2楼-- · 2019-01-16 06:45

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

Launch VS Code. Open the Command Palette (⇧⌘P) and type shell command to find the Shell Command: Install code command in PATH command. Mac shell commands

Restart the terminal for the new $PATH value to take effect. You'll be able to type code . in any folder to start editing files in that folder.

查看更多
可以哭但决不认输i
3楼-- · 2019-01-16 06:46

Sometimes setting path from 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 bottom of the file, and enter the path you wish to add
  3. Hit control-x to quit. Enter “Y” to save the modified buffer.
  4. Restart your terminal and to test echo $PATH. You should something similar

~ 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 navigate to your project folder from terminal

Enter:

code .

or

code /path/to/project

Source

查看更多
爷的心禁止访问
4楼-- · 2019-01-16 06:48

This will work

sudo code --user-data-dir="~/.vscode-root"
查看更多
Animai°情兽
5楼-- · 2019-01-16 06:53

In linux if you use code . it will open VS Code in the folder the terminal was in. Using code . Filename.cs it will open in folder and open said file.

查看更多
爷、活的狠高调
6楼-- · 2019-01-16 06:56

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

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

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

查看更多
Evening l夕情丶
7楼-- · 2019-01-16 06:59

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

I was trying to figure out how to open files with VS Code from the command line and I already had the capability - I just forgot I had already added it. You might already have it installed - check by navigating to a folder you want to open and running the command code . to open that folder.

查看更多
登录 后发表回答