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

前端 未结 25 2350
日久生厌
日久生厌 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:33

    Here are the steps which I followed to make it working on MAC:

    Install "Shell" extension from VSCode:

    Restart VSCode.

    Press F1 when VSCode is opened.

    Type "Shell" and select the following option: Shell Command: Install 'code' command in PATH command

    That will give you the following message: Shell command 'code' successfully installed in PATH.

    Running "which code" command will give you a proof the code command working now:

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

    Alternative to commandline Solution:

    Recently I was playing with Services in Mac OS X. I added a service to a folder or file so that I can open that folder or file in Visual Studio Code. I think this could be an alternative to using 'code .' command if you are using the Finder app. Here are the steps:

    • Open Automator App from Application. (Or you can use Spotlight).
    • Click on 'New Document' button to create a new script.
    • Choose 'Service' as a new type of document.
    • Select 'files and folders' in 'Service receives selected' dropdown.
    • Search for 'Open Finder Items' action item.
    • Drag that action item to the workflow area.
    • Select 'Visual Studio Code.app' application in the action 'Open with' dropdown.
    • Press 'command + s' to save the service. It will ask a name of service. Give it a name. I gave 'Open with VSCode'. Close the Automator app. Check the image below for more information.

    Verify:

    • Open the Finder app.
    • Right-click on any folder.
    • In the context menu, look for 'Open with VSCode' menu option.
    • Click on the 'Open with VSCode' menu option.
    • The folder should get open in the Visual Studio Code application. Check image below for more info.

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

    If you want to add it permanently:

    Add this to your ~/.bash_profile, or to ~/.zshrc if you are running MacOS Catalina or later.

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

    source: https://code.visualstudio.com/docs/setup/mac

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

    If you are on Windows and facing the same problem, have a look at this answer of @Inazense https://stackoverflow.com/a/52869803/4567504.

    In Visual studio code I was not able to find “Shell Command: Install 'code' command in PATH command.” so I had to do this manually.

    1. Open Environment Variables (System > Advance system settings > Advanced tab > environment variables) on system variables click on Path and click Edit and add new Path named

    "C:\Users\Your_Username\AppData\Local\Programs\Microsoft VS Code\bin"

    Now you are done! restart command prompt and try again

    0 讨论(0)
  • I foolishly deleted my /usr/local/bin/code symbolic link and did not know the correct path. A brew reinstall recreated it:

    brew cask reinstall visual-studio-code
    

    path turned out to be:

    /usr/local/bin/code ->
    '/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'
    
    0 讨论(0)
  • 2020-12-12 09:35

    If you have trouble using the Command Palette solution, you can manually add VS Code to the $PATH environment variable when your terminal starts:

    cat << EOF >> ~/.bash_profile
    # Add Visual Studio Code (code)
    export PATH="$PATH:/Applications/Visual Studio 
    Code.app/Contents/Resources/app/bin"
    EOF
    
    0 讨论(0)
提交回复
热议问题