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

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

pwd

/Users/mona/nodejs/myExpressApp

code .

-bash: code:命令不存在


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


当前回答

Use:

sudo rm /usr/local/bin/code

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

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

其他回答

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

添加到.bash_profile文件:

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

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

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

到VS顶部,选择菜单视图→命令面板…

通过⌘P打开命令面板,并输入shell命令到 查找Shell命令: [Windows]打开命令面板通过Ctrl+Shift+P和输入shell命令到 查找Shell命令:


类型:shell命令

和安装。

在Ubuntu 20.04 (Focal Fossa)中:

# Symbolic link the bin command to /usr/bin
rm -f /usr/bin/code
ln -s /usr/share/code/bin/code /usr/bin/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应用程序中打开。查看下面的图片了解更多信息。

对于Mac OS X,有三种方式可以启用代码。在Visual Studio Code中打开当前文件夹。

对于一个新的安装

通过Homebrew安装Visual Studio代码

有一种方法可以通过Brew-Cask安装Visual Studio代码。

首先,从这里安装Homebrew。 现在运行以下命令,它将在Mac上安装最新的Visual Studio代码。 酿造桶安装可视化工作室代码

上面的命令应该安装Visual Studio Code,并设置Visual Studio Code的命令行调用。

如果上述步骤不起作用,那么您可以手动执行。请遵循这里给出的Microsoft Visual Studio代码文档。

如果已经安装了Visual Studio Code

如果已经安装了Visual Studio Code,则无需重新安装。你可以选择下面两种方法中的任何一种。

选项1:更新Bash概要文件中的PATH

更新您最喜欢的Bash配置文件,例如~/。Bash_profile或~/。Bashrc或~/。导出Visual Studio Code应用程序的app/bin路径。您可以将下面的导出命令添加到您喜欢的Bash概要文件中。

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

选项2:使用Visual Studio代码命令面板

我们也可以在Visual Studio代码命令面板中运行shell命令。要做到这一点,我们需要通过(⌘P)打开命令面板,输入“shell Command”,找到名为:

Shell命令:在PATH中安装“code”命令

按“Enter”执行上述shell命令。

就是这样。