文档中提到了一种叫做代码的可执行文件,但我不确定在哪里可以找到它,所以我可以把它放在我的路径上。我从VSCode网站下载的zip文件不包括任何这样的可执行文件。(我可以很好地运行.app。)

这是windows独有的功能吗?


当前回答

从Visual Studio代码设置页面:

Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list. After installation, launch VS Code. Now open the Command Palette (F1 or ⇧+⌘+P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command. After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.

其他回答

如果你在下载文件夹中安装你的vs code,你需要将vs code移动到应用程序文件夹,然后打开vs code,然后按shift + command + p,你会看到下图。然后你需要输入代码。现在可以开始了。

将此添加到/usr/local/bin/code,如果它们不同,您可能需要修改路径。

#!/usr/bin/env bash

CONTENTS="/Applications/Visual Studio Code.app/Contents"
ELECTRON="$CONTENTS/MacOS/Electron"
CLI="$CONTENTS/Resources/app/out/cli.js"
ATOM_SHELL_INTERNAL_RUN_AS_NODE=1 "$ELECTRON" "$CLI" "$@"
exit $?

之后制作可执行文件

sudo chmod +x /usr/local/bin/code

从Visual Studio代码设置页面:

Tip: If you want to run VS Code from the terminal by simply typing 'code', VS Code has a command, Shell Command: Install 'code' command in PATH, to add 'code' to your $PATH variable list. After installation, launch VS Code. Now open the Command Palette (F1 or ⇧+⌘+P on Mac) and type shell command to find the Shell Command: Install 'code' command in PATH command. After executing the command, restart the terminal for the new $PATH value to take effect. You'll be able to simply type 'code .' in any folder to start editing files in that folder.

链接你当前的文件夹到vscode。

Windows Registry Editor Version 5.00

; Directory\Background\shell => on empty space

[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode]
"Icon"="C:\\current-folder-vscode\\Code.exe,0"
@="VsCode"

[HKEY_CLASSES_ROOT\Directory\Background\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."

; Directory\shell => on a folder

[HKEY_CLASSES_ROOT\Directory\shell\vscode]
@="VsCode"
"Icon"="C:\\current-folder-vscode\\Code.exe,0"

[HKEY_CLASSES_ROOT\Directory\shell\vscode\command]
@="C:\\current-folder-vscode\\Code.exe ."

在OSX Mavericks上,我在~/bin中创建了一个名为vscode的bash脚本(改编自vscode Setup中的.bashrc):

#!/bin/bash

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

Vscode <文件或目录>现在按预期工作。