命令代码。这本手册里没有。
之前的所有步骤都奏效了。如何在OS X终端中调用Visual Studio代码?
pwd
/Users/mona/nodejs/myExpressApp
code .
-bash: code:命令不存在
我最终通过改变工作空间从Visual Code Studio中打开它,但是为什么命令代码不会。部分工作?
命令代码。这本手册里没有。
之前的所有步骤都奏效了。如何在OS X终端中调用Visual Studio代码?
pwd
/Users/mona/nodejs/myExpressApp
code .
-bash: code:命令不存在
我最终通过改变工作空间从Visual Code Studio中打开它,但是为什么命令代码不会。部分工作?
当前回答
如果你想永久添加:
将此添加到~/。Bash_profile或~/。如果您运行的是macOS v10.15 (Catalina)或更高版本。
export PATH="$PATH:/Applications/Visual Studio Code.app/Contents/Resources/app/bin"
来源:macOS上的Visual Studio Code
其他回答
为此,需要在Bash路径中有一个名为“code”的可执行文件,这是一些安装程序为您添加的,但这个显然没有。
最好的方法是在/usr/local/bin文件夹中添加到Visual Studio Code应用程序的符号链接。您可以在终端中使用如下命令来完成此操作。
ln -s "/Path/To/Visual Studio Code" "/usr/local/bin/code"
您可能需要将sudo放在它的前面,以获得成功完成它的权限。
如果你在Windows上,也面临同样的问题,可以看看Inazense的答案,Visual Studio Code -“Shell Command: Install ' Code ' Command in PATH Command .”。
在Visual Studio代码中,我无法找到“Shell命令:在PATH命令中安装' Code '命令”。所以我不得不手动操作。
打开环境变量(系统→高级系统设置→高级选项卡→环境变量)。在系统变量中,单击Path,然后单击Edit,添加一个名为:
“C:用户/用户名/应用程序/微软/代码/ bin”
现在你完成了!重新启动命令提示符,然后重试。
按照文档将“code”安装到PATH是非常简单的,但它不起作用。
我只是先卸载了它,然后重新安装。
打开命令面板(⇧⌘P)
Shell Command: Uninstall 'code' command in PATH command.
然后重新安装。
Shell Command: Install 'code' command in PATH command.
重新启动终端以包含新的PATH。
命令行解决方案的替代方案:
最近我在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,但在重新启动Bash后禁用。如果你想要整合它,只需在PATH中创建一个代码文件; 我在usr/local/bin中创建了一个代码文件并添加
#!/usr/bin/env bash
function realpath() { python -c "import os,sys;print(os.path.realpath(sys.argv[1]))" "$0"; }
CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ELECTRON_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?
只需将这些内容替换为Visual Studio Code的安装路径。不要忘记使用chmod +x /usr/local/bin/code使其可执行。