Software - MS Code User Guide

VS Code 用户手册

常用命令

远程环境直开

code --folder-uri=vscode-remote://ssh-remote+HOSTNAME/FOLDER

code --file-uri=vscode-remote://ssh-remote+HOSTNAME/PATH.code-workspace

常用插件

插件名称 作用
Remote Development 配合 ~/.ssh/config 可编辑服务器端/WSL/容器内的文件

命令行安装插件 

code --install-extension vscjava.vscode-java-pack
code --install-extension ms-vscode.csharp
code --install-extension ms-python.python
code --install-extension ms-azuretools.vscode-docker    # Docker
code --install-extension eamodio.gitlens
# 远程开发套件
code --install-extension ms-vscode-remote.vscode-remote-extensionpack

常用设置

通过菜单 Code > Preferences > Settings 或者快捷键 Cmd + ,,可以用 JSON 配置 MS Code。

项目 作用
remote.WSL.server.connectThroughLocalhost true 通过 localhost 连接 WSL2
workbench.list.openMode doubleClick 取消单击预览
workbench.tree.expandMode doubleClick
window.openFoldersInNewWindow on 在新窗口打开文件夹
terminal.integrated.shell.linux /bin/zsh 设置默认 Shell

按扩展名指定语法高亮类型

配置 .exp 文件使用 TCL 高亮:

// 为指定扩展名文件关联高亮语言
"files.associations": {
    "*.exp": "tcl"
},

添加 vscode 至命令行

Cmd + Shiftp 选择 Shell Command : Install code in PATH,在命令行中即可使用 code 启动 VS Code。

Kubernets

跳过 resource limits 提醒:

"disable-linters": [
	"resource-limits"
]

XML Tools

Azure Portal 上下载的 .PublishSettings 文件没有换行,可以安装 XML Tools 后使用快捷键 Ctrl + Shift + Option + B 重新格式化当前打开的 XML 文件,结合以下设置,可使每个属性在独立一行,方便参考。

// 指定 XML 属性独立一行
"xmlTools.splitAttributesOnFormat": true

Log Viewer

监视对象在 VS Code 配置文件中定义:

{
    "logViewer.watch": [
        {
            "title": "nginx access",
            "pattern": "/var/log/nginx/access*.log"
        },
        {
            "title": "nginx error",
            "pattern": "/var/log/nginx/error*.log"
        }
    ]
}

快捷键

编辑

Ctrl / Cmd + D 多光标编辑

Ctrl + Shift + Option / Alt + B 格式化 XML 文件,需要安装 XML Tools 插件

Option 移动代码行或代码块

切换光标

// 命令行与编辑文档间
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus"},
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus"}

参考

Author: njun
njun's picture
Updated: 2023/09/13