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

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

pwd

/Users/mona/nodejs/myExpressApp

code .

-bash: code:命令不存在


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


当前回答

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

最近我在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应用程序中打开。查看下面的图片了解更多信息。

其他回答

如果你在使用命令面板解决方案时遇到问题,你可以在终端启动时手动将Visual Studio Code添加到$PATH环境变量中:

cat << EOF >> ~/.bash_profile
# Add Visual Studio Code (code)
export PATH="$PATH:/Applications/Visual Studio
Code.app/Contents/Resources/app/bin"
EOF

以下步骤:

打开Visual Studio Code应用程序,键入Command + Shift + P并键入命令 安装代码。然后进入。 您将在Visual Studio Application中看到以下消息:shell命令' 代码成功安装在PATH中。 现在,跳转到iTerm CLI并键入代码。 然后,您将能够重定向到Visual Studio Code进行任何代码更改/视图。

按照文档将“code”安装到PATH是非常简单的,但它不起作用。

我只是先卸载了它,然后重新安装。

打开命令面板(⇧⌘P)

Shell Command: Uninstall 'code' command in PATH command.

然后重新安装。

Shell Command: Install 'code' command in PATH command.

重新启动终端以包含新的PATH。

在我的Mac上,我让它运行起来:

添加到.bash_profile文件:

code() {
   open -a Visual\ Studio\ Code.app $1
}

保存并在终端中执行source .bash_profile。

然后在终端中,code index.html(或其他什么)将在Visual Studio code中打开该文件。

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

最近我在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应用程序中打开。查看下面的图片了解更多信息。