How to open Visual Studio Code from the command line on OSX?

后端 未结 24 1122
日久生厌
日久生厌 2020-11-30 16:20

The docs mention an executable called code, but I\'m not sure where I can find that so I can put it on my path. The zip I downloaded from the VSCode site did no

相关标签:
24条回答
  • 2020-11-30 17:14

    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-11-30 17:15

    I had this issue because of VS Code Insiders. The path variable was there but I needed to rename the code-insiders.cmd inside to code.cmd .

    Maybe this is useful to someone.

    0 讨论(0)
  • 2020-11-30 17:17

    If you want to open a file or folder on Visual Studio Code from your terminal, iTerm, etc below are the commands which come as default when you install Visual Studio Code

    To open Visual Studio Code from command line

    code --
    

    To open the entire folder/directory

    code .
    

    To open a specific file

    code file_name
    eg:- code index.html
    
    0 讨论(0)
  • 2020-11-30 17:17

    This was the tutorial I was looking for in this thread. It shows the way to open files in Visual Studio Code by writing code .

    1.- Open the file

    Bash

                    open ~/.bash_profile 
    

    Terminal OS

                        open ~/.zshrc
    

    2.- Add in your file the :

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

    3.- Reinicialize terminal and try in the folder you want to open

             code .
    

    4.- Then you can use it as shown in this comment: https://stackoverflow.com/a/41821250/10033560

    0 讨论(0)
  • 2020-11-30 17:18

    We since updated the script to the following syntax to support multiple files and folders as arguments and to fix an issue with not detecting the current working directory properly:

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

    Update for our VS Code 1.0 release:

    Please use the command Install 'Code' command in path or Install 'code-insiders' command in path from the command palette (View | Command Palette) to make Code available to the command line.

    0 讨论(0)
  • 2020-11-30 17:18

    For me on Macbook Book Pro 2019 MacOS version 10.15.6, shortcut to open command palette in VSCode was Shift + Command + P.

    On opening it one has to just write install code and press enter.

    After that just open the terminal and type code your vscode will start opening.

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