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

后端 未结 24 1123
日久生厌
日久生厌 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条回答
  • I ran: open -a "Visual Studio Code" [folder-name] to open a folder with my Visual Studio Code application. Folder name is optional if you just want to open the application. Not sure if this is exactly your use-case, but hope this helps!

    0 讨论(0)
  • This is what worked for me on Mac OS Catalina -- found here (thanks, Josiah!)

    If you're on Mac OS Catalina, you need to edit your .zprofile instead of .bash_profile.

    1. Edit your ~/.zprofile file: vim ~/.zprofile
    2. Add the following code in it, on it's own line: code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
    3. Save the file: :wq
    4. Re-run the updated file: source ~/.zprofile.
    5. Test that running code . opens your current folder in VS Code!
    0 讨论(0)
  • 2020-11-30 17:19

    I have a ~/bin/code shell script that matches the command @BengaminPasero wrote.

    #!/bin/bash
    VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
    

    I prefix ~/bin: to my $PATH which allows me to add a bunch of one off scripts without polluting my ~/.bash_profile script.

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

    For windows Users just type in

    >code .
    

    More commands here https://code.visualstudio.com/docs/editor/command-line

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

    From the Visual Studio Code Setup page:

    Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list.

    After installation, launch VS Code. Now open the Command Palette (F1 or ++P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command.

    After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.

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

    You can use the vscode: protocol that Visual Studio Code defines:

    open vscode://file/full/path/to/project/or/file
    

    You can also use

    /Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
    

    if you do not fancy modifying your path

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