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

之前的所有步骤都奏效了。如何在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

其他回答

下面是我在Mac上使用它的步骤:

从Visual Studio Code安装“Shell”扩展:

重新启动Visual Studio代码。

打开Visual Studio Code时按F1。

输入“Shell”并选择以下选项: Shell命令:在PATH命令中安装“code”命令:

这将给你以下消息: Shell命令“code”已成功安装在PATH中。

运行"which code"命令将给你一个'code'命令正在工作的证明:

注意:对于Visual Studio Code 1.58(2021年6月)的Code Insiders,您有Microsoft/Visual Studio Code issue 126702(适用于Windows,但也适用于Mac)。

code-insiders。不打开当前目录。相反,它为代码内部人员打开了路径。

这个问题已经解决了。

Mac OS X

下载Visual Studio Code for Mac OS X。 双击onvcode -osx.zip展开内容。 拖动Visual Studio Code。将app移到Applications文件夹中,使其在Launchpad中可用。 通过右键单击图标并选择“选项”,“保持在Dock中”,将Visual Studio代码添加到Dock中。

提示:如果您想从终端运行Visual Studio Code,请将以下内容附加到~/。Bash_profile文件(~/.)zshrc如果你使用Z shell(可执行zsh))。

code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}

现在,您可以简单地键入代码。在任何文件夹中开始编辑该文件夹中的文件。

设置代码。只要一秒钟

只需按照以下步骤执行一个简单的命令:

打开Visual Studio Code应用程序 Command + Shift + P 输入命令'install code'。然后进入。

嘣,搞定了。

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