在terminal/iterm2中快速打开vscode
- 打开vscode命令面板,搜索
Shell
, 选择在 PATH 中安装 “Code” 命令 - 在terminal/iterm2的项目目录执行
code
即可打开vscode
- 使用
code -r
复用当前窗口 - 使用
code -g <file:line>
打开文件,然后滚动到文件中某个特定的行 - 使用
code -d <file1> <file2>
比较两个文件 - 使用
<command> | code -
在vscode中显示管道内容
常用插件
- Chinese language pack
- 支持中文
- Code Runner
- 单独运行一个文件
- Settings Sync
- 同步所有vscode配置
- shift+alt+U 上传配置
- shift+alt+D 下载配置
- gitLens
- 查看git的commit,文件等信息
- remote
- 远程编译和debug
- 支持SSH,WSL,Docker
- TODO Highlight
- 高亮TODO注释
- Bracket Pair Colorizer
- 给括号涂色
- TabOut
- TAB跳出括号
- shell-format
- 格式化shell, dockerfile等文件
- VS Live Share
- 共享协作信息(精确到光标位置)
- REST client
- 类似Postman
- Docker
- 查看本地的容器,镜像,数据卷等信息
变量
${workspaceFolder}
- 工作区目录
{fileBasename}
- 当前文件的文件名
{fileBasenameNoExtension}
- 当前文件的文件名,不带后缀
${file}
- 当前打开正在编辑的文件名,包括绝对路径,文件名,文件后缀名
${fileDirname}
- 文件所在的文件夹路径
${env:PATH}
- 系统中的环境变量
参考:https://code.visualstudio.com/docs/editor/variables-reference
断点
- 右键断点可以设置额外属性
- Hit count
- 运行多少次后才中断
- Expression condition
- 条件为真才中断
配置文件
settings.json
- User Settings作用于全局
- Workspace Settings作用于工作区
launch.json
- 用来配置debugger
- 字段含义
- preLaunchTask
- 在运行debugger之前,按照tasks.json配置属性
- args
- 命令行参数
- stopOnEntry
- 自动停止在程序开始处
- program
- 程序运行的路径
- 可用上文的变量配置
- 可根据所处平台自动调用不同配置
- "osx"代指mac平台
"args": ["myFolder/path/app.js"],
"windows": {
"args": ["myFolder\\path\\app.js"]
}
tasks.json
- 用来配置编译命令
- 可根据所处平台自动调用不同配置
通用配置
// 主题
"workbench.colorTheme": "One Dark Pro",
"workbench.iconTheme": "vscode-icons",
"window.zoomLevel": 0,
"debug.console.fontSize": 18,
// 终端
"terminal.integrated.fontSize": 18,
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
// 同步vscode配置
"sync.gist": "XXXXX",
"sync.autoUpload": true,
// 文件
"files.autoSave": "afterDelay",
"files.trimTrailingWhitespace": true,
"explorer.confirmDragAndDrop": false,
"explorer.confirmDelete": false,
// 编辑器
"editor.fontSize": 20,
"editor.formatOnSave": true,
"editor.autoIndent": false,
"editor.suggestSelection": "first",
"editor.formatOnPaste": true,
"editor.formatOnSave": true,
"editor.wordWrap": "on",
"editor.codeActionsOnSave": {
"source.organizeImports": true
},
// git
"git.confirmSync": false,
"git.autofetch": true,
"diffEditor.ignoreTrimWhitespace": true,
Go
settings.json
"[go]": {
"editor.defaultFormatter": "ms-vscode.Go",
},
"go.gotoSymbol.includeGoroot": true,
"go.gotoSymbol.includeImports": true,
"go.installDependenciesWhenBuilding": true,
"go.buildOnSave": "off",
"go.buildFlags": [],
"go.buildTags": "",
"go.coverOnSingleTest": true,
"go.useCodeSnippetsOnFunctionSuggest": true,
"go.useCodeSnippetsOnFunctionSuggestWithoutType": true,
"go.autocompleteUnimportedPackages": true,
"go.docsTool": "guru",
"go.formatTool": "goimports",
"go.formatFlags": [],
"go.lintTool": "golangci-lint",
"go.lintOnSave": "package",
"go.lintFlags": [
"--fast"
],
"go.vetFlags": [],
"go.vetOnSave": "package",
"go.generateTestsFlags": [],
"go.liveErrors": {
"enabled": true,
"delay": 500
},
"go.gocodePackageLookupMode": "go",
"go.gocodeAutoBuild": true,
"go.gocodeFlags": [
"-builtin",
"-ignore-case",
"-unimported-packages"
],
"go.enableCodeLens": {
"references": true,
"runtest": true
},
"go.delveConfig": {
"dlvLoadConfig": {
"followPointers": true,
"maxVariableRecurse": 1,
"maxStringLen": 64,
"maxArrayValues": 64,
"maxStructFields": -1
},
"apiVersion": 2,
"showGlobalVariables": true
},
"go.editorContextMenuCommands": {
"toggleTestFile": true,
"addTags": true,
"removeTags": true,
"testAtCursor": true,
"testFile": true,
"testPackage": true,
"generateTestForFunction": true,
"generateTestForFile": true,
"generateTestForPackage": true,
"addImport": true,
"testCoverage": true,
"playground": true,
"debugTestAtCursor": true
},
"go.playground": {
"openbrowser": false,
"share": false,
"run": false
},
"go.addTags": {
"tags": "json",
"options": "json=omitempty",
"promptForTags": true,
"transform": "snakecase"
},
"go.removeTags": {
"tags": "",
"options": "",
"promptForTags": false
}
C/C++
launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch", // 配置名称,将会在启动配置的下拉菜单中显示
"type": "cppdbg", // 配置类型,这里只能为cppdbg
"request": "launch", // 请求配置类型,可以为launch(启动)或attach(附加)
"program": "${fileDirname}/${fileBasenameNoExtension}", // 将要进行调试的程序的路径
"args": [], // 程序调试时传递给程序的命令行参数,一般设为空即可
"stopAtEntry": false, // 设为true时程序将暂停在程序入口处,我一般设置为true
"cwd": "${workspaceFolder}", // 调试程序时的工作目录
"environment": [], // 环境变量
"externalConsole": true, // 调试时是否显示控制台窗口,一般设置为true显示控制台
"internalConsoleOptions": "neverOpen", // 如果不设为neverOpen,调试时会跳到“调试控制台”选项卡,你应该不需要对gdb手动输命令吧?
"MIMode": "gdb", // 指定连接的调试器,可以为gdb或lldb。但目前lldb在windows下没有预编译好的版本。
"miDebuggerPath": "gdb", // 调试器路径,Windows下后缀不能省略,Linux下则去掉
"setupCommands": [ // 用处未知,模板如此
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": false
}
],
"preLaunchTask": "Compile" // 调试会话开始前执行的任务,一般为编译程序。与tasks.json的label相对应
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "compile", // 任务名称,与launch.json的preLaunchTask相对应
"command": "/usr/bin/g++", // 要使用的编译器
"args": [
"-Wall", // 开启额外警告
//"-static-libgcc", // 静态链接
"-std=c++11", // C语言最新标准为c11,或根据自己的需要进行修改
"-g", // 生成和调试有关的信息
"${file}",
"-o", // 指定输出文件名,不加该参数则默认输出a.exe,Linux下默认a.out
"${fileDirname}/${fileBasenameNoExtension}"
], // 编译命令参数
"type": "shell", // 可以为shell或process,前者相当于先打开shell再输入命令,后者是直接运行命令
// 以下命令非必须,可删
// "group": {
// "kind": "build",
// "isDefault": true // 设为false可做到一个tasks.json配置多个编译指令,需要自己修改本文件,我这里不多提
// },
// // https://code.visualstudio.com/docs/editor/tasks#_output-behavior
// "presentation": {
// "echo": true,
// "reveal": "always", // 在“终端”中显示编译信息的策略,可以为always,silent,never。具体参见VSC的文档
// "focus": false, // 设为true后可以使执行task时焦点聚集在终端,但对编译c和c++来说,设为true没有意义
// "panel": "shared" // 不同的文件的编译信息共享一个终端面板
// },
// // https://code.visualstudio.com/docs/editor/tasks#_processing-task-output-with-problem-matchers
// "problemMatcher": {
// "owner": "cpp",
// "fileLocation": [
// "relative",
// "\\"
// ],
// "pattern": {
// "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
// "file": 1,
// "line": 2,
// "column": 3,
// "severity": 4,
// "message": 5
// }
// }
}
]
}
c_cpp_properties.json
// windows下
{
"configurations": [
{
"name": "MinGW",
"intelliSenseMode": "clang-x64",
"compilerPath": "C:/mingw-w64/mingw64/bin/g++.exe",
"includePath": [
"${workspaceFolder}"
],
"defines": [],
"browse": {
"path": [
"${workspaceFolder}"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"cStandard": "c11",
"cppStandard": "c++11"
}
],
"version": 4
}
// linux下
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
Git比较
- 可以将vscode作为sourcetree外部比较器和合并器
LaTeX
- 首先要安装 Tex Live
- 下载 .iso 文件
- 右键 install-tl-advanced.bat,以管理员身份运行
- 和前面一样,也要写入环境变量
- 如
C:\texlive\2017\bin\win32
- 在vscode中安装 LaTex Workshop 拓展
- 然后我们调整用户设置
- vscode默认的编译器是pdflatex和latexmk,而我更喜欢用自动支持中文的xelatex,于是我在设置中将其设置为默认编译器
- 默认为直接xelatex编译一次就好,但是当设计到引用文件的时候就要 xe->bib->xe->xe 四次编译才行,当然我一般不加引用文件
- 更多的配置我在下面的代码中已经注释好了,将其加入全局用户设置就好了
"latex-workshop.latex.tools": [
{
// 编译工具和命令
"name": "xelatex",
"command": "xelatex",
"args": [
"-synctex=1",
"-interaction=nonstopmode",
"-file-line-error",
"%DOC%"
]
},
{
"name": "bibtex",
"command": "bibtex",
"args": [
"%DOCFILE%"
]
}
],
"latex-workshop.latex.recipes": [
//默认编译方式
{
"name": "xelatex",
"tools": [
"xelatex"
]
},
{
"name": "xe->bib->xe->xe",
"tools": [
"xelatex",
"bibtex",
"xelatex",
"xelatex"
]
}
],
//禁止保存时自动编译
"latex-workshop.latex.autoBuild.onSave.enabled": false,
//默认内置查看器
"latex-workshop.view.pdf.viewer": "tab",
//是否删除临时文件
"latex-workshop.latex.clean.enabled": false,
//右键菜单
"latex-workshop.showContextMenu": true,
- 右键 build LaTeX project 执行默认编译选项
- 或者可以点击左下角的对勾符号选择编译方式
- 右上角执行默认预览
- 或者可以点击左下角的对勾符号选择预览方式
- 右键 synctex with cursor 由代码跳转到PDF内容,预览器中Ctrl+鼠标左键由内容跳转到代码
- 或者可以使用Ctrl+alt+J 快捷键由代码到内容
- 注意路径一定是全英文且无空格和引号的!
更多自定义配置
关联WSL
将用户设置中terminal.integrated.shell.windows项的路径修改为 C:\Windows\System32\wsl.exe
即:
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\wsl.exe",
此时默认的终端即为ubuntu了
修改键盘映射
因为键盘的方向键举例字母区太远,所以决定通过alt+jkl;来映射方向键
- 打开左下角的键盘快捷方式
- 打开右上角{}图标编辑json文件
- 把下面的代码复制到keybindings.json文件中
// 将密钥绑定放在此文件中以覆盖默认值
[
{
"key": "alt+j",
"command": "cursorLeft"
},
{
"key": "alt+k",
"command": "cursorUp"
},
{
"key": "alt+l",
"command": "cursorDown"
},
{
"key": "alt+;",
"command": "cursorRight"
}
]
在文件资源管理器中不显示exe文件
在设置中搜索files.exclude项,并添加"**/*.exe":true