如何从 OSX 上的命令行打开 Visual Studio 代码?
How to open Visual Studio Code from the command line on OSX?
docs 提到了一个名为 code
的可执行文件,但我不确定在哪里可以找到它,所以我可以将它放在我的路径中。我从 VSCode 站点下载的 zip 文件不包含任何此类可执行文件。 (我可以 运行 .app
就好了。)
这是 Windows 独有的东西吗?
来自Visual Studio Code Setup page:
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.
在 OSX Mavericks 我在 ~/bin
中创建了一个名为 vscode
的 bash 脚本(改编自 VSCode Setup 中的 .bashrc
):
#!/bin/bash
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ = /* ]] && F="" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
vscode <file or directory>
现在可以正常工作了。
此后,我们将脚本更新为以下语法,以支持将多个文件和文件夹作为参数,并解决无法正确检测当前工作目录的问题:
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
我们的 VS Code 1.0 版本更新:
请使用命令选项板 (View | Command Palette
) 中的命令 Install 'Code' command in path
或 Install 'code-insiders' command in path
使代码可用于命令行。
我发现了一个适用于 mingw32 的巧妙解决方法(即对于那些使用由 git-scm.com 在 windows 上安装的 bash 版本的人):
code () { VSCODE_CWD="$PWD" cmd //c code $* ;}
我有一个 ~/bin/code
shell 脚本匹配@BengaminPasero 写的命令。
#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
我在我的 $PATH
前加上 ~/bin:
前缀,这样我就可以添加一堆一次性脚本,而不会污染我的 ~/.bash_profile
脚本。
将此添加到 /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
我遇到这个问题是因为 VS Code Insiders。
路径变量在那里,但我需要将里面的代码 insiders.cmd 重命名为 code.cmd .
也许这对某人有用。
如果您想打开 Visual Studio 上的文件或文件夹 来自 terminal
、iTerm
等的代码 下面是安装 [=24] 时默认出现的命令=]代码
从命令行打开 Visual Studio 代码
code --
打开整个folder/directory
code .
打开特定文件
code file_name
eg:- code index.html
我 运行: open -a "Visual Studio Code" [folder-name]
使用我的 Visual Studio 代码应用程序打开一个文件夹。如果您只想打开应用程序,文件夹名称是可选的。不确定这是否正是您的用例,但希望这对您有所帮助!
VS Code Command Line处给出的启动路径的指令不正确;示例中显示的前导冒号不起作用。但是,以反斜杠终止的目录名称启动会按预期打开指定的目录。
所以,例如,
code C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src\
打开目录 C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src
中的 Visual Studio 代码编辑器。
重要提示: 终端反斜杠虽然是可选的,但很有用,因为它清楚地表明打算打开一个 目录,而不是文件。请记住,文件名 扩展名 是并且一直是可选的。
注意: 附加到 PATH 列表的目录是 \bin
目录,shell 命令 code
启动一个Windows NT 命令脚本.
因此,当合并到另一个 shell 脚本中时,code
必须 called 或 started 如果您期望脚本的其余部分为 运行。值得庆幸的是,我在第一次测试新的 shell 脚本之前发现了这一点,我正在创建该脚本以在本地 Web 服务器、我的默认 Web 浏览器和 Visual Studio 代码中启动一个 Angular 2 项目, 一次全部。
以下是我的 Angular 启动脚本,适用于消除对我在其他地方发布但并非严格要求的系统实用程序之一的依赖。
@echo off
转到 SKIPREM
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:SKIPREM
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause
⚡️ The Easy Solution.
- 下载、安装并打开 Visual Studio Code。
- 打开命令面板(⌘ + ⇧ + P on Mac) 或 查看 ❯ 命令面板
3. Type shell command
to find
Shell Command: Install 'code' command in PATH command
- 安装它就大功告成了
这是免费的 GIF。
之后,您可以在终端中使用code
或code .
。
code
和平! ✌️
如果您想更深入地了解一些使用 VSCode CLI 的重要 tips/tricks,我在我的工作流程中做了 a YouTube video。
对于 windows 用户
只需输入
>code .
这里有更多命令
https://code.visualstudio.com/docs/editor/command-line
您可以使用 vscode:
协议 Visual Studio Code defines:
open vscode://file/full/path/to/project/or/file
您也可以使用
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
如果你不喜欢modifying your path
这就是我在此线程中寻找的教程。它展示了通过编写代码在Visual Studio代码中打开文件的方法。
1.- 打开文件
Bash
open ~/.bash_profile
航站楼OS
open ~/.zshrc
2.- 在您的文件中添加:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
3.- 重新初始化终端并在您要打开的文件夹中尝试
code .
4.- 然后你可以使用它,如评论所示:
打开 VSC 并按 (Command + Up + P) 后,我尝试输入“shell command”,但没有任何反应。为了让“Shell 命令:在 PATH 命令中安装 'code' 命令”出现,您必须执行以下操作:
按(命令,向上,P)
键入 >
(这将显示 运行 命令)
然后输入Shell Command: Install 'code' command in PATH command
。然后它应该出现。
点击后,它会更新,您应该可以开始了!
Note: Only for Windows Users.
许多人已经提出了使用 code .
命令从命令提示符打开代码的方法。这只会打开 Visual Studio Code Stable 构建。但是如果你已经下载了 Visual Studio Code Insider build/version(它有所有最新的 build/features 但不稳定的版本)那么你需要按照下面的说明进行操作 windows :
- 转到控件 Panel\System 和 Security\System。点击高级系统设置
- 点击环境变量
- 在“系统变量”选项卡下,单击“编辑路径变量”
- 添加新路径
C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin
(或)
C:\Program Files\Microsoft VS Code Insiders\bin
基于您在计算机中安装 vscode insider 的位置。
打开 new 命令提示符并键入 code-insiders .
以打开 vscode-insider
build/version
很简单:
从命令行启动
您还可以在终端中 运行 VS Code,方法是在将其添加到路径后键入 'code':
启动 VS 代码。
打开命令面板 (⇧⌘P) 并键入“shell command”以找到 Shell 命令:在 PATH 命令中安装 'code' 命令。
来源
如果你在下载文件夹中安装你的 vs 代码,你需要将 VS 代码移动到应用程序文件夹,然后打开 vs 代码,然后按 shift
+
command
+
p
之后你会看到 下图。然后您需要输入 code .
现在您可以开始了。
link 您当前的文件夹 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 ."
试试这个
打开 Visual Studio 代码并按 Command + Shift + P 然后在命令面板中键入 Shell 现在您可以找到此选项,例如 Shell 命令:在 PATH 中安装代码来自命令面板中的建议列表。 Select那个选项。
通过Terminal/Command提示打开VSCode
就是这样。
现在打开你的终端类型。
$代码.
这就是我在 Mac OS Catalina 上工作的方法——发现 here(谢谢,Josiah!)
如果您使用的是 Mac OS Catalina,则需要编辑您的 .zprofile 而不是 .bash_profile.
- 编辑您的 ~/.zprofile 文件:
vim ~/.zprofile
- 在它自己的行中添加以下代码:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
- 保存文件::wq
- 重新运行更新后的文件:
source ~/.zprofile
.
- 测试 运行ning
code .
在 VS Code 中打开当前文件夹!
如果您使用 snap
安装 VS CODE。您需要在 PATH 环境变量中添加 /snap/bin
。
所以 - 打开你的 .bashrc
或 .zshrc
并在您的 PATH 环境变量
中添加 /snap/bin
重新加载终端,
然后 code
命令将启动它
如果您使用的是 VS Code Insiders:
code-insiders .
如果您使用的是 VS Code:
code .
对于我在 Macbook Book Pro 2019 MacOS 版本 10.15.6 上,在 VSCode 中打开命令面板的快捷方式是 Shift
+ Command
+ P
.
打开它时只需输入 install code
并按 enter
。
之后只需打开终端并输入 code
您的 vscode 将开始打开。
对于Windows,您可以使用命令:
start Code filename.extension
上面一行对我有用。
如果您正在使用 visual code insiders
并且想从您的终端或任何其他命令行工具打开 Visual Studio Code insider
中的文件或文件夹,那么您可以参考下面的命令默认在 visual studio code insider
.
内
从命令行打开Visual Studio代码
code-insiders --
打开整个folder/directory
code-insiders .
打开特定文件
code-insiders file_name
例如:-代码index.html
在我的例子中,我不得不使用别名:
alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
您可以在 ~/.bash_profile
中添加此别名。
$> open -a "Visual Studio 代码" [文件名]
VSCode 现在支持开箱即用 with version 1.58。只需输入:
$ cd path/to/your/directory
$ code .
我已将此添加到我的 ~/.profile
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'
然后
. ~/.profile
之后我就可以了
vscode
从终端
只需将您的 python 更新为 python3.9 我做到了并且对我有用。
docs 提到了一个名为 code
的可执行文件,但我不确定在哪里可以找到它,所以我可以将它放在我的路径中。我从 VSCode 站点下载的 zip 文件不包含任何此类可执行文件。 (我可以 运行 .app
就好了。)
这是 Windows 独有的东西吗?
来自Visual Studio Code Setup page:
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 theShell 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.
在 OSX Mavericks 我在 ~/bin
中创建了一个名为 vscode
的 bash 脚本(改编自 VSCode Setup 中的 .bashrc
):
#!/bin/bash
if [[ $# = 0 ]]
then
open -a "Visual Studio Code"
else
[[ = /* ]] && F="" || F="$PWD/${1#./}"
open -a "Visual Studio Code" --args "$F"
fi
vscode <file or directory>
现在可以正常工作了。
此后,我们将脚本更新为以下语法,以支持将多个文件和文件夹作为参数,并解决无法正确检测当前工作目录的问题:
code () {
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
}
我们的 VS Code 1.0 版本更新:
请使用命令选项板 (View | Command Palette
) 中的命令 Install 'Code' command in path
或 Install 'code-insiders' command in path
使代码可用于命令行。
我发现了一个适用于 mingw32 的巧妙解决方法(即对于那些使用由 git-scm.com 在 windows 上安装的 bash 版本的人):
code () { VSCODE_CWD="$PWD" cmd //c code $* ;}
我有一个 ~/bin/code
shell 脚本匹配@BengaminPasero 写的命令。
#!/bin/bash
VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $*
我在我的 $PATH
前加上 ~/bin:
前缀,这样我就可以添加一堆一次性脚本,而不会污染我的 ~/.bash_profile
脚本。
将此添加到 /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
我遇到这个问题是因为 VS Code Insiders。 路径变量在那里,但我需要将里面的代码 insiders.cmd 重命名为 code.cmd .
也许这对某人有用。
如果您想打开 Visual Studio 上的文件或文件夹 来自 terminal
、iTerm
等的代码 下面是安装 [=24] 时默认出现的命令=]代码
从命令行打开 Visual Studio 代码
code --
打开整个folder/directory
code .
打开特定文件
code file_name
eg:- code index.html
我 运行: open -a "Visual Studio Code" [folder-name]
使用我的 Visual Studio 代码应用程序打开一个文件夹。如果您只想打开应用程序,文件夹名称是可选的。不确定这是否正是您的用例,但希望这对您有所帮助!
VS Code Command Line处给出的启动路径的指令不正确;示例中显示的前导冒号不起作用。但是,以反斜杠终止的目录名称启动会按预期打开指定的目录。
所以,例如,
code C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src\
打开目录 C:\Users\DAVE\Documents\Programming\Angular\StringCalculator\src
中的 Visual Studio 代码编辑器。
重要提示: 终端反斜杠虽然是可选的,但很有用,因为它清楚地表明打算打开一个 目录,而不是文件。请记住,文件名 扩展名 是并且一直是可选的。
注意: 附加到 PATH 列表的目录是 \bin
目录,shell 命令 code
启动一个Windows NT 命令脚本.
因此,当合并到另一个 shell 脚本中时,code
必须 called 或 started 如果您期望脚本的其余部分为 运行。值得庆幸的是,我在第一次测试新的 shell 脚本之前发现了这一点,我正在创建该脚本以在本地 Web 服务器、我的默认 Web 浏览器和 Visual Studio 代码中启动一个 Angular 2 项目, 一次全部。
以下是我的 Angular 启动脚本,适用于消除对我在其他地方发布但并非严格要求的系统实用程序之一的依赖。
@echo off
转到 SKIPREM
=========================================================================
Name: StartAngularApp.CMD
Synopsis: Start the Angular 2 application installed in a specified
directory.
Arguments: %1 = OPTIONAL: Name of directory in which to application
is installed
Remarks: If no argument is specified, the application must be in
the current working directory.
This is a completely generalized Windows NT command
script (shell script) that uses the NPM Angular CLI to
load an Angular 2 application into a Node development
Web server, the default Web browser, and the Visual
Studio Code text editor.
Dependencies: Unless otherwise specified in the command line, the
application is created in the current working directory.
All of the following shell scripts and programs must be
installed in a directory that is on the Windows PATH
directory list.
1) ShowTime.CMD
2) WWPause.exe
3) WWSleep.exe
4) npm (the Node Package Manager) and its startup
script, npm.cmd, must be accessible via the Windows
PATH environment string. By default, this goes into
directory C:\Program Files\nodejs.
5) The Angular 2 startup script, ng.cmd, and the Node
Modules library must be installed for global access.
By default, these go into directory %AppData%\npm.
Author: David A. Gray
Created: Monday, 23 April 2017
-----------------------------------------------------------------------
Revision History
-----------------------------------------------------------------------
Date By Synopsis
---------- --- --------------------------------------------------------
2017/04/23 DAG Script created, tested, and deployed.
=======================================================================
:SKIPREM
echo BOJ %~0, version %~t0
echo.
echo -------------------------------------------------------
echo Displaying the current node.js version:
echo -------------------------------------------------------
echo.
node -v
echo.
echo -------------------------------------------------------
echo Displaying the current Node Package Manager version:
echo -------------------------------------------------------
echo.
call npm -v
echo.
echo -------------------------------------------------------
echo Loading Angular starter application %1
echo into a local Web server, the default Web browser, and
echo the Visual Studio Code text editor.
echo -------------------------------------------------------
echo.
if "%1" neq "" (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %1
echo -------------------------------------------------------
echo.
cd "%~1"
call code %1\src\
) else (
echo.
echo -------------------------------------------------------
echo Starting the Angular application in directory %CD%
echo -------------------------------------------------------
echo.
call code %CD%\src\
)
call ng serve --open
echo.
echo -------------------------------------------------------
echo %~nx0 Done!
echo -------------------------------------------------------
echo.
Pause
⚡️ The Easy Solution.
- 下载、安装并打开 Visual Studio Code。
- 打开命令面板(⌘ + ⇧ + P on Mac) 或 查看 ❯ 命令面板
3. Type
shell command
to findShell Command: Install 'code' command in PATH command
- 安装它就大功告成了
这是免费的 GIF。
之后,您可以在终端中使用code
或code .
。
code
和平! ✌️
如果您想更深入地了解一些使用 VSCode CLI 的重要 tips/tricks,我在我的工作流程中做了 a YouTube video。
对于 windows 用户 只需输入
>code .
这里有更多命令 https://code.visualstudio.com/docs/editor/command-line
您可以使用 vscode:
协议 Visual Studio Code defines:
open vscode://file/full/path/to/project/or/file
您也可以使用
/Applications/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code
如果你不喜欢modifying your path
这就是我在此线程中寻找的教程。它展示了通过编写代码在Visual Studio代码中打开文件的方法。
1.- 打开文件
Bash
open ~/.bash_profile
航站楼OS
open ~/.zshrc
2.- 在您的文件中添加:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
3.- 重新初始化终端并在您要打开的文件夹中尝试
code .
4.- 然后你可以使用它,如评论所示:
打开 VSC 并按 (Command + Up + P) 后,我尝试输入“shell command”,但没有任何反应。为了让“Shell 命令:在 PATH 命令中安装 'code' 命令”出现,您必须执行以下操作:
按(命令,向上,P)
键入
>
(这将显示 运行 命令)然后输入
Shell Command: Install 'code' command in PATH command
。然后它应该出现。点击后,它会更新,您应该可以开始了!
Note: Only for Windows Users.
许多人已经提出了使用 code .
命令从命令提示符打开代码的方法。这只会打开 Visual Studio Code Stable 构建。但是如果你已经下载了 Visual Studio Code Insider build/version(它有所有最新的 build/features 但不稳定的版本)那么你需要按照下面的说明进行操作 windows :
- 转到控件 Panel\System 和 Security\System。点击高级系统设置
- 点击环境变量
- 在“系统变量”选项卡下,单击“编辑路径变量”
- 添加新路径
C:\Users\tsabu\AppData\Local\Programs\Microsoft VS Code Insiders\bin
(或)C:\Program Files\Microsoft VS Code Insiders\bin
基于您在计算机中安装 vscode insider 的位置。
打开 new 命令提示符并键入code-insiders .
以打开 vscode-insider build/version
很简单:
从命令行启动
您还可以在终端中 运行 VS Code,方法是在将其添加到路径后键入 'code':
启动 VS 代码。 打开命令面板 (⇧⌘P) 并键入“shell command”以找到 Shell 命令:在 PATH 命令中安装 'code' 命令。
来源
如果你在下载文件夹中安装你的 vs 代码,你需要将 VS 代码移动到应用程序文件夹,然后打开 vs 代码,然后按 shift
+
command
+
p
之后你会看到 code .
现在您可以开始了。
link 您当前的文件夹 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 ."
试试这个
打开 Visual Studio 代码并按 Command + Shift + P 然后在命令面板中键入 Shell 现在您可以找到此选项,例如 Shell 命令:在 PATH 中安装代码来自命令面板中的建议列表。 Select那个选项。
通过Terminal/Command提示打开VSCode
就是这样。
现在打开你的终端类型。
$代码.
这就是我在 Mac OS Catalina 上工作的方法——发现 here(谢谢,Josiah!)
如果您使用的是 Mac OS Catalina,则需要编辑您的 .zprofile 而不是 .bash_profile.
- 编辑您的 ~/.zprofile 文件:
vim ~/.zprofile
- 在它自己的行中添加以下代码:
code () { VSCODE_CWD="$PWD" open -n -b "com.microsoft.VSCode" --args $* ;}
- 保存文件::wq
- 重新运行更新后的文件:
source ~/.zprofile
. - 测试 运行ning
code .
在 VS Code 中打开当前文件夹!
如果您使用 snap
安装 VS CODE。您需要在 PATH 环境变量中添加 /snap/bin
。
所以 - 打开你的 .bashrc
或 .zshrc
并在您的 PATH 环境变量
/snap/bin
重新加载终端,
然后 code
命令将启动它
如果您使用的是 VS Code Insiders:
code-insiders .
如果您使用的是 VS Code:
code .
对于我在 Macbook Book Pro 2019 MacOS 版本 10.15.6 上,在 VSCode 中打开命令面板的快捷方式是 Shift
+ Command
+ P
.
打开它时只需输入 install code
并按 enter
。
之后只需打开终端并输入 code
您的 vscode 将开始打开。
对于Windows,您可以使用命令:
start Code filename.extension
上面一行对我有用。
如果您正在使用 visual code insiders
并且想从您的终端或任何其他命令行工具打开 Visual Studio Code insider
中的文件或文件夹,那么您可以参考下面的命令默认在 visual studio code insider
.
从命令行打开Visual Studio代码
code-insiders --
打开整个folder/directory
code-insiders .
打开特定文件
code-insiders file_name
例如:-代码index.html
在我的例子中,我不得不使用别名:
alias code="/<PATH TO VSCODE>/Visual\ Studio\ Code.app/Contents/Resources/app/bin/code"
您可以在 ~/.bash_profile
中添加此别名。
$> open -a "Visual Studio 代码" [文件名]
VSCode 现在支持开箱即用 with version 1.58。只需输入:
$ cd path/to/your/directory
$ code .
我已将此添加到我的 ~/.profile
alias vscode='/Applications/Visual\ Studio\ Code.app/Contents/MacOS/Electron'
然后
. ~/.profile
之后我就可以了
vscode
从终端
只需将您的 python 更新为 python3.9 我做到了并且对我有用。