How to call VS Code Editor from terminal / command line

前端 未结 21 1359
别那么骄傲
别那么骄傲 2020-12-04 06:22

The question says it all.

How can I open VS Code editor from

  • windows cmd
  • linux and mac terminal

e.g. for notepad++ I write

相关标签:
21条回答
  • 2020-12-04 06:57

    On Ubuntu the flatpak version seemed broken. I uninstalled it and downloaded the deb package right from Microsoft.

    0 讨论(0)
  • 2020-12-04 07:00

    This works for Windows:

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

    But if the filepath has spaces, normally one would add double quotes around it, like this:

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

    But this messes up with start, which can take a double-quoted title, so it will create a window with this name as the title and not open the project.

    CMD> start "title" "vscode://file/o:/git/lib zmq/builds/msvc/vs2017/libzmq.sln"
    
    0 讨论(0)
  • 2020-12-04 07:03

    Per the docs:

    Mac OS X

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

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

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

    Now, you can simply type code . in any folder to start editing files in that folder.

    Tip: You can also add it to VS Code Insiders build by changing "com.microsoft.VSCodeInsiders". Also if you don't to type the whole word code, just change it to c.

    Linux

    1. Download Visual Studio Code for Linux.
    2. Make a new folder and extract VSCode-linux-x64.zip inside that folder.
    3. Double click on Code to run Visual Studio Code.

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

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

    Now, you can simply type code . in any folder to start editing files in that folder.

    0 讨论(0)
  • 2020-12-04 07:03

    If you install VS CODE using snap. You will need to add /snap/bin in your PATH environment variable. so - open your .bashrc or .zshrc and add :/snap/bin in your PATH environment variable reload terminal, and than code comand will start it

    0 讨论(0)
  • 2020-12-04 07:04

    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.

    0 讨论(0)
  • 2020-12-04 07:05

    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 .

    0 讨论(0)
提交回复
热议问题