- 一般来说,vscode运行程序需要三个json文件,分别是settings.json, launch.json, tasks.json
- settings.json进行配置
- launch.json进行运行
- 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": "golint",
"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
},
// gopls
"go.useLanguageServer": false,
"go.languageServerFlags": [],
"go.alternateTools": {
"go-langserver": "gopls"
},
"go.languageServerExperimentalFeatures": {
"format": true,
"autoComplete": true,
"rename": true,
"goToDefinition": true,
"hover": true,
"signatureHelp": true,
"goToTypeDefinition": true,
"goToImplementation": true,
"documentSymbols": true,
"workspaceSymbols": true,
"findReferences": true,
"diagnostics": true,
"documentLink": true
}
launch.json
未完成
tasks.json
未完成
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
}
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 快捷键由代码到内容
-
注意路径一定是全英文且无空格和引号的!