在windows上打造最佳的vscode开发flow


8/2/2019 windows vscode wsl

大家都知道,windows 上的 terminal 难用,但自从微软拥抱开源拥抱 linux 后,引入了子系统 linux 发行版,那用起来还真是不错的。

安装 linux 子系统

实际上,官方有详细的文档

一般来说,我会选择直接去应用商店去下载。

打开 Microsoft Store,选择喜爱的 Linux 发行版

这里我选择 Ubuntu 18.04 LTS

fawn8bnei946xbt9.png

打开链接,点击右上方获取,即可跳转应用商店,点击下载安装。

初始化

安装后,必须先初始化新的发行版实例一次,然后才能使用它。需要输入用户名和密码。

qdlvzf20dveoecdi.png

安装必备神器

安装zsh

# 安装zsh
$ sudo apt-get install zsh
 # 将zsh设置为默认shell
$ chsh -s /bin/zsh
1
2
3
4

安装oh my zsh

# 安装oh my zsh
$ wget https://github.com/robbyrussell/oh-my-zsh/raw/master/tools/install.sh -O - | sh
1
2

选择主题

# 打开配置文件
$ vim ~/.zshrc
1
2
# 将ZSH-THEME改成ys
ZSH_THEME="ys"
1
2
# 更新配置
$source ~/.zshrc
1
2

安装zsh插件

git 是默认安装的 z colored-man-pages 是自带的

其他需要下载之后才能用

安装 zsh-autosuggestions 插件

$ git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions

编辑~/.zshrc 文件

$ vim ~/.zshrc

plugins=(git zsh-autosuggestions)
1

安装 zsh-syntax-highlighting 插件

$ git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting

编辑~/.zshrc 文件

$ vim ~/.zshrc

plugins=(git zsh-autosuggestions zsh-syntax-highlighting)
1

$ source ~/.zshrc

安装 node

nvm是nodejs的一个版本管理工具

# install nvm using curl
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | zsh`

# or install nvm using wget
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.1/install.sh | zsh`

# install lts
nvm install 10.24.0

# 检查安装是否成功
node -v
1
2
3
4
5
6
7
8
9
10
11

解决git在windows 和 linux上差异

在linux上 $ git config core.autocrlf true

在cmd/powershell上 $ git config core.autocrlf

参考:https://github.com/Microsoft/WSL/issues/1352

在vscode上切换终端

理论上,vscode上只能设置一个默认终端,如果需要切换必须 reload 才行。

但有一个插件可以帮我们解决问题:Shell launcher ew2hhkmbbgmsra4i.png

配置

"shellLauncher.shells.windows": [
    {
        "shell": "C:\\Windows\\System32\\cmd.exe",
        "label": "cmd"
    },
    {
        "shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
        "label": "PowerShell"
    },
    {
        "shell": "C:\\Program Files\\Git\\bin\\bash.exe",
        "label": "Git bash"
    },
    {
        "shell": "C:\\Windows\\System32\\wsl.exe",
        "label": "WSL Bash"
    }
]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

增加切换快捷指令

打开快捷指令,搜索shellLauncher.launch,配置快捷键ctrl+shift+t

[{
    "key": "ctrl+shift+t",
    "command": "shellLauncher.launch"
}]
1
2
3
4

这样,每次只需要 ctrl+shift+t 快捷键,就可以一键切换终端。

Last Updated: 12/27/2019, 7:42:06 AM