“code .” Not working in Command Line for Visual Studio Code on OSX/Mac

前端 未结 25 2222
日久生厌
日久生厌 2020-12-12 09:13

The command \"code .\" doesn\'t work in this manual?

All the other steps before that worked. How can I call the Visual Studio Code in OSX terminal?

         


        
相关标签:
25条回答
  • 2020-12-12 09:39

    For those of you that run ZShell with Iterm2, add this to your ~/.zshrc file.

    alias code="/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
    
    0 讨论(0)
  • 2020-12-12 09:40

    1. Make sure you drag Visual Studio Code app into the -Applications- folder

    Otherwise (as noted in the comments) you'll have to go through this process again after reboot


    2. Next, open Visual Studio Code

    Open the Command Palette via (⇧⌘P) 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. The "." Simply means "current directory"

    (Source: VS Code documentation)


    NOTE: If you're running a build based off the OSS repository... You will need to run code-oss . @Dzeimsas Zvirblis

    0 讨论(0)
  • 2020-12-12 09:40

    Define the path of the Visual Studio in your ~/.bash_profile as follow

    export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"

    0 讨论(0)
  • 2020-12-12 09:41

    For code . to work in OSX terminal append code as described here https://code.visualstudio.com/Docs/setup but instead of to .bashrc, in OSX try .profile which is loaded at terminal session start.

    0 讨论(0)
  • 2020-12-12 09:42

    https://code.visualstudio.com/Docs/setup

    Tip: If you want to run VSCode from the terminal, append the following to your .bashrc file

    code () {
    if [[ $# = 0 ]]
    then
        open -a "Visual Studio Code"
    else
        [[ $1 = /* ]] && F="$1" || F="$PWD/${1#./}"
        open -a "Visual Studio Code" --args "$F"
    fi
    }
    

    Then $ source ~/.bashrc

    0 讨论(0)
  • 2020-12-12 09:42

    EDIT: If this is happening on mint/ubuntu, it is likely because you installed vscode through the software manager. This will cause other problems during debugging. Instead install it using the .deb file on the vscode website.

    If you really want to use the software manager, the solution below still works:

    use find / -name code 2> /dev/null to find the path to the visual studio bin file. It should end in /extra/vscode/bin/code

    If you're using the mint software manager, you might only find paths with a ridiculously long name in the middle like this:

    ".../stable/7a22830d9e8fbbdc9627e43e072005eef66c14d2a4dd19992427ef4de060186a/..."

    Just replace the long part with "/active/"

    Once you have it, create a sym link:

    ln -s path_you_found/extra/vscode/bin/code /usr/local/bin/code

    If you don't have the rights, or only want it to be accessible for yourself, simply add this line to your .bashrc / .zshrc:

    export PATH="$PATH:path_you_found/extra/vscode/bin/

    Note that I removed the 'code' filename at the end

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