Visual Studio Code 打开 WSL 中的文件


#Windows#


步骤1、Windows 10 中安装 Visual Studio Code

官网下载安装即可。

安装好后,我们可以在命令提示符中使用 code 命令打开它。

步骤2、Visual Studio Code 安装 Remote WSL 插件

该插件的作用是:

Open any folder in the Windows Subsystem for Linux (WSL) and take advantage of Visual Studio Code's full feature set.

步骤3、安装 WSL

假设安装了 Ubuntu 20.04。

步骤4、进入 WSL 终端,执行 code 命令

例如执行 code ~/.zshrc,第一次,会下载 VS Code Server for x64

$ code ~/.zshrc
Installing VS Code Server for x64 (3c4e3df9e89829dce27b7b5c24508306b151f30d)
Downloading: 100%
Unpacking: 100%
Unpacked 1719 files and folders to /home/letian/.vscode-server/bin/3c4e3df9e89829dce27b7b5c24508306b151f30d.

执行完成后,Windows 的 Visual Studio Code 会启动,并展示 WSL 中 ~/.zshrc 文件的内容。

2021-09: 从近期的使用情况看,vs code 无法在命令行直接打开 WSL 系统的文件,在尝试打开一个文件时,会不停的弹窗。但可以打开一个目录。


( 本文完 )