命令代码。这本手册里没有。

之前的所有步骤都奏效了。如何在OS X终端中调用Visual Studio代码?

pwd

/Users/mona/nodejs/myExpressApp

code .

-bash: code:命令不存在


我最终通过改变工作空间从Visual Code Studio中打开它,但是为什么命令代码不会。部分工作?


当前回答

参见设置Visual Studio代码

提示:如果你想在终端上运行Visual Studio Code,请在.bashrc文件中添加以下文件:

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

然后输入~/.bashrc

其他回答

1. 确保将Visual Studio Code应用程序拖到Applications文件夹中

否则(如评论中所述),您将不得不在重新启动后再次执行此过程。


2. 接下来,打开Visual Studio Code

通过⌘P打开命令面板,输入shell命令,找到shell命令:

在“在PATH中安装代码”命令之前,请先使用PATH命令中的卸载代码命令。

执行该命令后,重新启动终端以获取新的$PATH 值生效。你可以简单地在任何 文件夹中开始编辑该文件夹中的文件。“。”简单地说就是“当前目录”

(来源:Visual Studio Code文档)


注意:如果您正在运行基于OSS存储库的构建,则需要运行code-oss。(泽姆萨斯·兹维尔布利斯的评论)

这很简单。在你的终端机上打这个。你可以使用第一个或第二个命令:

cat << EOF >> ~/.bash_profile
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

然后按“Enter”。

但是,由于Z shell成为macOS Catalina的默认shell,运行以下命令将Visual Studio Code添加到您的路径:

cat << EOF >> ~/.zprofile
export PATH="\$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
EOF

我使用了最新的命令,它对我有用。

我愚蠢地删除了/usr/local/bin/code符号链接,不知道正确的路径。Homebrew重装重新创建:

brew cask reinstall visual-studio-code

这条路原来是:

/usr/local/bin/code ->
'/Applications/Visual Studio Code.app/Contents/Resources/app/bin/code'

Use:

sudo rm /usr/local/bin/code

打开Visual Studio Code,然后按Ctrl + Shift + P

然后写命令安装代码,你会得到一个弹出窗口。然后按照指示做!

命令行解决方案的替代方案:

最近我在Mac OS x中使用服务。我向文件夹或文件添加了服务,这样我就可以在Visual Studio Code中打开该文件夹或文件。我认为如果你正在使用Finder应用程序,这可以替代使用'code .'命令。

以下是步骤:

Open Automator App from Application (or you can use Spotlight). Click on the 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 the '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 Visual Studio Code'. Close the Automator app. Check the image below for more information.

验证:

打开Finder应用程序。 右键单击任何文件夹。 在上下文菜单中,寻找“使用Visual Studio Code打开”菜单选项。 点击“用Visual Studio Code打开”菜单选项。 该文件夹应该在Visual Studio Code应用程序中打开。查看下面的图片了解更多信息。