Windows

VS Code

PowerToys

Snipaste

PicGo

WSL2

TeX Live

Windows Subsystem for Linux

Shell

zsh

将zsh作为默认的 Shell 环境 chsh -s $(which zsh)

插件

配置与 GitHub 连接的 SSH 密钥

  • 在 WSL 下生成 SSH 公钥 — 私钥对(将邮箱替换为你的邮箱),此时生成的 SSH 密钥默认位于 ~/.ssh 路径下,公钥为 id_rsa.pub,私钥为 id_rsa

    $ ssh-keygen -t rsa -b 4096 -C "email@ex.com"
  • 打开 ssh-agent 使之在后台运行:

    $ eval "$(ssh-agent -s)"
  • 将私钥添加到 ssh-agent 之中:

    $ ssh-add ~/.ssh/id_rsa
  • 查看公钥并将之复制到剪贴板:

    # 查看公钥内容
    $ cat ~/.ssh/id_rsa.pub
     
    # 将公钥复制到剪贴板
    $ cat ~/.ssh/id_rsa.pub | clip.exe
  • 将复制好的公钥添加到 GitHub 账户密钥里面:Adding a new SSH key to your GitHub account - GitHub Help.

  • 通过命令 ssh -T git@github.com 来测试是否能够登录成功。

配置代理

~/.zshrc 或你使用的 Shell 的配置文件中添加内容,实现自动化配置代理:

# Fetch Windows ip address inside WSL environment
WINDOWS_IP=$(ip route | grep default | awk '{print $3}')
PROXY_HTTP="http://${WINDOWS_IP}:7890"
PROXY_SOCKS5="${WINDOWS_IP}:7890"
 
# Git & SSH for Git proxy
proxy_git () {
  git config --global http.https://github.com.proxy ${PROXY_HTTP}
  if ! grep -qF "Host github.com" ~/.ssh/config ; then
    echo "Host github.com" >> ~/.ssh/config
    echo "  User git" >> ~/.ssh/config
    echo "  ProxyCommand nc -X 5 -x ${PROXY_SOCKS5} %h %p" >> ~/.ssh/config
  else
    lino=$(($(awk '/Host github.com/{print NR}'  ~/.ssh/config)+2))
    sed -i "${lino}c\  ProxyCommand nc -X 5 -x ${PROXY_SOCKS5} %h %p" ~/.ssh/config
  fi
}
 
# Set proxy
set_proxy () {
  export http_proxy="${PROXY_HTTP}"
  export https_proxy="${PROXY_HTTP}"
  proxy_git
}
 
# Unset proxy
unset_proxy () {
  unset http_proxy
  unset https_proxy
  git config --global --unset http.https://github.com.proxy
}
 
# Set alias
alias proxy=set_proxy
alias deproxy=unset_proxy

其中:

  • 第一行 WINDOWS_IP=$(ip route | grep default | awk '{print $3}') 让我们使用 WSL 2 时可以自动获取最新的 WSL IP 地址,WSL 1 可以直接将 WINDOWS_IP 设置为 127.0.0.1
  • 之后的 PROXY_HTTPPROXY_SOCKS5 分别是我们代理的 HTTP 协议地址和 SOCKS5 地址;
  • 函数 proxy_git() 让我们直接设置 Git 自己的代理和 ssh 登录 GitHub 的代理;
  • 后续的 set_proxy()unset_proxy() 就分别是设定 Git 代理和环境变量,以及取消 Git 代理、删除环境变量;

v2ray

查看宿主机IP和端口,使用命令:ip route | grep default | awk '{print $3},在v2ray主界面可以看到http代理端口。

export hostip=$(ip route | grep default | awk '{print $3}')
export hostport=10809
alias proxy='
    export https_proxy="http://${hostip}:${hostport}";
    export http_proxy="http://${hostip}:${hostport}";
    export all_proxy="http://${hostip}:${hostport}";
    git config --global http.proxy "http://${hostip}:${hostport}"
    git config --global https.proxy "http://${hostip}:${hostport}"
    echo -e "Acquire::http::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
    echo -e "Acquire::https::Proxy \"http://${hostip}:${hostport}\";" | sudo tee -a /etc/apt/apt.conf.d/proxy.conf > /dev/null;
'
alias deproxy='
    unset https_proxy;
    unset http_proxy;
    unset all_proxy;
    git config --global --unset http.proxy
    git config --global --unset https.proxy
    sudo sed -i -e '/Acquire::http::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
    sudo sed -i -e '/Acquire::https::Proxy/d' /etc/apt/apt.conf.d/proxy.conf;
'

使用命令 proxydeproxy 即可开关代理。

VS Code

个性化

字体

  • Fira Code
  • FiraCode Nerd Font Mono
  • JetBrains Mono

主题

  • GitHub Theme
  • Material Icon Theme
  • Dracula Refined
  • Everforest
  • Dracula

插件

  • LeetCode
  • Vim
  • Code Runner
  • C/C++ (Pre-Release Version)
  • CMake
  • CMake Tools (Pre-Release Version)
  • WSL
  • Error Lens
  • CodeLLDB

VS Code JSON

// settings.json
{
    "editor.fontFamily": "'Fira Code Retina', 'Cascadia Mono', '思源宋体'",
    "terminal.integrated.fontFamily": "'FiraCode Nerd Font Mono'"
    "workbench.colorTheme": "GitHub Light",
    "workbench.iconTheme": "material-icon-theme",
    "vim.useSystemClipboard": true,
    "vim.sneak": true,
    "vim.camelCaseMotion.enable": true,
    "vim.easymotion": true,
    "vim.highlightedyank.enable": true,
    "vim.hlsearch": true,
    "vim.handleKeys": {
        "<C-c>": false,
        "<C-z>": false,
        "<C-y>": false,
        "<C-x>": false,
        "<C-v>": false,
    },
    "vim.replaceWithRegister": true,
    "vim.smartRelativeLine": true,
    "vim.sneakUseIgnorecaseAndSmartcase": true,
    "vim.targets.enable": true,
    "vim.visualstar": true,
}
// keybindings.json
[
    {
        "key": "alt+j",
        "command": "selectNextSuggestion",
        "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus || suggestWidgetVisible && textInputFocus && !suggestWidgetHasFocusedSuggestion"
    },
    {
        "key": "alt+k",
        "command": "selectPrevSuggestion",
        "when": "suggestWidgetMultipleSuggestions && suggestWidgetVisible && textInputFocus || suggestWidgetVisible && textInputFocus && !suggestWidgetHasFocusedSuggestion"
    }
]

Vim Shortcuts

A Good Tutorial Video: Youtube, Bilibili

n stands for NORMAL mode, i stands for INSERT mode, v stands for VISUAL mode.

Open and Close Files

ModeShortcutDescription
n:wWrite(save) current buffer
n:qClose current buffer (would fail if you don't save first)
n:wqSave and close current buffer
n:q!Exit current buffer without saving
n:qa!Exit all open buffers without saving
n:wqaSave and exit all open buffers
ModeShortcutDescription
n, vhMove left
n, vjMove down
n, vkMove up
n, vlMove right
n, vwOne word forward
n, vbOne word backward
n, v^Beginning of line
n, v$End of line
n, vggBeginning of file
n, vGEnd of file
n, v{One paragraph backward
n, v}One paragraph forward
n, vf + [char]Move to next occurence of [char] in current line (Covered in Part 2 video)
n, vF + [char]Move to prev occurence of [char] in current line (Covered in Part 2 video)
n, vCtrl+uMove Up half a Page (Covered in Part 2 video)
n, vCtrl+dMove Down half a Page (Covered in Part 2 video)
n, vCtrl+bMove Up a Full Page (Covered in Part 2 video)
n, vCtrl+fMove Down a Full Page (Covered in Part 2 video)
n:[num-of-line] + EnterGo to a specific line
n, v/[search-item] + Enter + nFind pattern and go to next match

Enter INSERT Mode from NORMAL Mode

ModeShortcutDescription
niInsert before cursor
naAppend after cursor
nIInsert at the beginning of the line
nAAppend at the end of the line
noInsert to next line
nOInsert to previous line
nc + [Navigation]Delete from before the cursor to [Navigation] and insert. Examples are as follow
nc + wDelete from before the cursor to end of current word and insert
nc + i + wDelete current word and insert
nc + $Delete from before the cursor to end of the line and insert
i<Esc>Go back to Normal Mode, remap to jk recommended

Enter INSERT Mode from NORMAL Mode

ModeShortcutDescription
niInsert before cursor
naAppend after cursor
nIInsert at the beginning of the line
nAAppend at the end of the line
noInsert to next line
nOInsert to previous line
nc + [Navigation]Delete from before the cursor to [Navigation] and insert. Examples are as follow
nc + wDelete from before the cursor to end of current word and insert
nc + i + wDelete current word and insert
nc + $Delete from before the cursor to end of the line and insert
i<Esc>Go back to Normal Mode, remap to jk recommended

Edit in NORMAL Mode

ModeShortcutDescription
nddDelete(cut) current line
nd + [Number] + d Or [Number] + ddDelete(cut) following [Number] of lines
nd + [Navigation]Delete(cut) from before the cursor to [Navigation], similar to c + [Navigation] above
nyyYank(copy) current line
ny + [Number] + y Or [number] + yyYank(copy) following [Number] of lines
ny + [Navigation]Yank(copy) from before the cursor to [Navigation], similar to c + [Navigation] above
npPaste from what you delete or yank
nxDelete(cut) the character under the cursor
nuUndo changes
nCtrl+rRedo changes
n:%s/[foo]/[bar]/gFind each occurrence of [foo] (in all lines), and replace it with [bar]. More substitute commands here.

VISUAL mode shortcuts

ModeShortcutDescription
nvEnter Visual Character Mode
nVEnter Visual Line Mode
V-Line>; <Increase Indent; Decrease Indent
nCtrl+vEnter Visual Block Mode
v<Esc>Exit Visual Mode, remap to jk recommended

Vim settings under VSCode

  1. Press Ctrl/Cmd+Shift+p in VSCode
  2. Find Preferences: Open User Settings (JSON), open settings.json
  3. Configure the file, all options are here

VScode Vim

Edit in NORMAL

PackageShortcutDescriptionRemap Needed?
VimgbMutlicursor operation
VScodeCtrl+nRename all the pattern that is under the cursorkeybindings.json
Vim Commentarygcc / gc5jToggle comment on this line / next 5 line(not including current line)
EasyMotion<leader><leader>s+[char]Quick navigation to [char] on the screen(more motion on doc)
Vim-surroundys[motion][symbol], ysiw)Yank [symbol] around [motion], the example means surround the word under the cursor with ()
Vim-surroundcs[symbol][newsymbol]Change [symbol] to [newsymbol] when your cursor is within the [symbol]
Vim Sneak<operator>z<char><char>Do [operator] until the next occurence of <char><char>
Vim Sneak3dzqtAn example: Delete everything until the next 3rd occurence of qt

Tab, File and Window Navigation

PackageShortcutDescriptionRemap Needed?
VSCodectrl + dToggle peek definitionkeybindings.json
VimgdGo to Definition
VimghHover doc
VScodecmd/ctrl+pSearch file by name and open
Vimtp, tn, tf, tlIn the current editor group: prev tab, next tab, first tab, last tabsettings.json
VScodectrl+zSwitch focus between editor and terminalkeybindings.json
VScodecmd/ctrl+jHide Terminal
VScodecmd/ctrl+bToggle File explorer

Editor Group Navigation

PackageShortcutDescriptionRemap Needed?
VSCodectrl + \Split Editorkeybindings.json
VSCodectrl + h/lMove to left/right editor groupkeybindings.json
VSCodecmd/ctrl + k + wClose all tabs in active editor group

For the emulated Vim plugins, some of them need to turn them on in settings.json as well, refer to the doc to see if that is required.

// settings.json
{
  "vim.useCtrlKeys": true,
  "vim.handleKeys": {
      "<C-c>": false,
      "<C-z>": false,
      "<C-x>": false,
      "<C-v>": false,
      "<C-f>": false,
      "<C-y>": false,
  },
  "vim.useSystemClipboard": true,
  "vim.insertModeKeyBindings": [
    {
      "before": ["i", "i"],
      "after": ["<Esc>"]
    }
  ],
  "vim.visualModeKeyBindings": [
    {
      "before": ["i", "i"],
      "after": ["<Esc>"]
    }
  ],
  "vim.normalModeKeyBindings": [
    {
      "before": ["<leader>", "t", "n"],
      "commands": [":tabnext"]
    },
    {
      "before": ["<leader>", "t", "p"],
      "commands": [":tabprev"]
    },
    {
      "before": ["<leader>", "t", "f"],
      "commands": [":tabfirst"]
    },
    {
      "before": ["<leader>", "t", "l"],
      "commands": [":tablast"]
    }
  ],
  "vim.ignorecase": false,
  "vim.leader": " ",
  "vim.easymotion": true,
  "vim.sneak": true,
  "vim.surround": true,
  "vim.statusBarColorControl": true,
  "vim.statusBarColors": {
    "normal": "#005f5f",
    "insert": "#5f0000",
    "visual": "#5f00af",
    "visualline": "#005f87",
    "visualblock": "#86592d",
    "replace": "#000000"
  },
  "workbench.colorCustomizations": {
    "statusBar.background": "#5f0000",
    "statusBar.noFolderBackground": "#5f0000",
    "statusBar.debuggingBackground": "#5f0000"
  }
}
 
// keybindings.json
[
  { "key": "ctrl+d", "command": "editor.action.peekDefinition" },
  {
    "key": "ctrl+d",
    "command": "editor.closeTestPeek",
    "when": "testing.isInPeek && !config.editor.stablePeek || testing.isPeekVisible && !config.editor.stablePeek"
  },
  { "key": "ctrl+n", "command": "editor.action.rename" },
  { "key": "ctrl+z", "command": "workbench.action.terminal.focus" },
  {
    "key": "ctrl+z",
    "command": "workbench.action.focusActiveEditorGroup",
    "when": "terminalFocus"
  },
  { "key": "ctrl+m", "command": "workbench.action.toggleEditorWidths" },
  { "key": "ctrl+\\", "command": "workbench.action.splitEditor" },
  { "key": "ctrl+h", "command": "workbench.action.navigateLeft" },
  { "key": "ctrl+l", "command": "workbench.action.navigateRight" },
  { "key": "ctrl+w", "command": "workbench.action.closeEditorsAndGroup" }
]