VSCode配置笔记

之前尝试了很多次配置VSCode,对这款功能强大的编辑器垂涎已久.但是因为网上的资料参差不齐,加上每个人电脑的编译器安装情况不同,所以一直没有配置成功.得力于Kevin00大佬的协助,总算是把VSCode给折腾 出来了.在下面记录一下配置的流程,以便之后查阅.

编译篇

环境变量

因为已经安装了Dev-Cpp,所以不需要另外安装Mingw了.环境变量的配置也极为简单,见下图:

(前面有两行是Python的配置)

Json配置

launch

{
    // 使用 IntelliSense 了解相关属性。 
    // 悬停以查看现有属性的描述。
    // 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(gdb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": " {file}.exe",
            "args": [],
            "stopAtEntry": false,
            // "cwd": "{workspaceFolder}",     // .vscode的上一级绝对路径(打开的工作文件夹)。eg: xxxx/cpp(cpp文件夹下就有.vscode文件夹)
            "cwd": "${fileDirname}",            // 当前编译.cpp文件所在绝对路径。eg: xxxx/cpp/CF/A(or B or C or...)
            "environment": [],
            "externalConsole": true,
            "preLaunchTask": "build",
            "MIMode": "gdb",
            "miDebuggerPath": "C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/gdb.exe", //斜杠必须这么打,不然会报错
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
        }
    ]
}

tasks

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",

            "args": [
                "-g",
                "-std=c++11",

 //               "-Wshadow",
                "-Wswitch",
                "-Wuninitialized",
                "-Wmaybe-uninitialized",
                "-Wformat",
                "-Wreturn-type",
                "-Wparentheses",
                "-Wunused-parameter",
                "-Wunused-but-set-parameter",
                "-Wfloat-equal",
                "-Wsizeof-pointer-memaccess",
                "-Waddress",
                "-Warray-bounds",
                "-Wempty-body",

                "{file}",
                "-o",
                "{file}.exe"
            ],
        }
    ]
}

c_cpp_properties

{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**",
                "C:\\Program Files (x86)\\DevCpp\\MinGW64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include\\c++",
                "C:\\Program Files (x86)\\DevCpp\\MinGW64\\lib\\gcc\\x86_64-w64-mingw32\\4.9.2\\include\\c++\tr1",
                "C:/Program Files (x86)/DevCpp/MinGW64/lib/gcc/x86_64-w64-mingw32/4.9.2/include/c++/x86_64-w64-mingw32"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "compilerPath": "C:\\Program Files (x86)\\Dev-Cpp\\MinGW64\\bin\\gcc.exe",
            "cStandard": "c11",
            "cppStandard": "c++11",
            "intelliSenseMode": "clang-x64"
        }
    ],
    "version": 4
}

上面的一些路径和Dev的安装路径有关,其余不要变动.C++版本选择的是C++11,C++14因为玄学原因不支持.注意放代码的文件夹的目录里不要含有中文,不然会导致GDB报一些奇怪的错误.

配色篇

再次感谢Kevin00大佬提供的的配色方案.据说里面注释的信息都是一个个试出来的Orz(当初VSCode还不给这些提示).以后隔一段时间会进行一次更新,以赶上微调的进度.

{
    "window.zoomLevel": 0,

    "editor.renderIndentGuides": true,
    "editor.cursorWidth": 3,


    "editor.fontSize": 16,

    "workbench.commandPalette.history": 200,

    "C_Cpp.default.cppStandard": "c++17",
    "editor.hover.delay": 400,
    "editor.quickSuggestionsDelay": 0,
    "editor.autoClosingBrackets": "always", // 左侧工具栏四个大按钮是否可见

    "editor.trimAutoWhitespace": false, // 终端光标是否闪烁

    "editor.suggestSelection": "recentlyUsedByPrefix",      // 智能自动补全(按照历史补全记录)


    // "workbench.colorCustomizations":
    // {
    //     "[Default Dark+]":
    //     {
    //         "editorCursor.foreground": "#abcf48",
    //         "editorBracketMatch.background": "#1b799638",
    //         "editorBracketMatch.border": "#68a4c5",
    //     }
    // },

    // "comments": "#81aac0",
    // "strings": "#bb8d7b",
    // "functions": "#f7f7f7",
    // "keywords": "#68dfff",
    // "types": "#ebd9b4",
    // "variables": "#f1f1f1",
    // "numbers": "#ff646e",

    "workbench.colorCustomizations":
    {
        "[Default Dark+]":
        {
            "foreground": "#f1f1f1",
            "errorForeground": "#51dae4",
            "editor.foreground": "#f1f1f1",

            // 编辑器
            "editor.background": "#181819",
            "activityBar.border": "#1a1a1a",                        // 左侧边栏分割线
            "editorIndentGuide.background": "#232327",              // 未激活缩进参考线
            "editorIndentGuide.activeBackground": "#757d8a",        // 激活缩进参考线
            "editorCursor.foreground": "#5260ff",                   // 光标颜色     abcf48,00ffff,ff525b

            // 行号
            "editorLineNumber.activeForeground": "#31ffff",
            "editorLineNumber.foreground": "#3a3a3f",
            "editorGutter.addedBackground": "#ff0000",
            "editorGutter.modifiedBackground": "#ff0000",
            "editorGutter.commentRangeForeground": "#ff0000",
            "editorGutter.deletedBackground": "#ff0000",

            // 选中、悬停和停止
            "editor.lineHighlightBorder": "#255e85",                // 光标所在行边框颜色
            "editor.lineHighlightBackground": "#19191a",            // 光标所在行填充颜色
            "editor.selectionForeground": "#39393b",                // 选中内容的文本叠加颜色
            "editor.selectionBackground": "#283441",                // 选中内容的背景颜色
            "editor.selectionHighlightBackground": "#1c2c4191",     // 与所选择的字符匹配的字符
            "editor.selectionHighlightBorder": "#3c4c58ca",
            "editor.hoverHighlightBackground": "#49495c6b",         // 悬停处文字背景叠加颜色


            // 资源管理器
            "sideBar.background": "#1b1b1c",                      // 资源管理器栏背景色
            "sideBar.foreground": "#848488",                      // 资源管理器栏前景色
            "sideBar.border": "#25252a",                          // 资源管理器栏边框色
            "sideBarTitle.foreground": "#cccccc",                 // 资源管理器标题色
            "sideBarSectionHeader.foreground": "#52ceffda",       // 工作区标题色
            "sideBarSectionHeader.background": "#28282a",

            // 资源管理器列表项
            "list.hoverForeground": "#00fff2",
            "list.hoverBackground": "#212123",
            "list.errorForeground": "#da6b6b",
            "list.activeSelectionBackground": "#2a2a2d",          // 选中时刻的背景颜色
            "list.activeSelectionForeground": "#00fff2",          // 选中时刻的前景颜色
            "list.inactiveSelectionBackground": "#212123",        // 选之后的背景颜色
            "list.inactiveSelectionForeground": "#d8d8d8",        // 选之后的前景颜色

            // 侧边栏(最左)
            "activityBar.background": "#212123",
            "activityBar.foreground": "#50e3ee",
            "activityBar.inactiveForeground": "#9e9e9e",


            // 标题栏(最顶部)
            "titleBar.activeBackground": "#222226",               // 标题栏颜色(最顶部)
            "titleBar.inactiveForeground": "#66666a",             // 窗口未选中时的标题栏颜色
            // 标题栏左侧的菜单栏
            "menu.background": "#27272aa4",
            "menu.foreground": "#cecfd3",
            "menu.separatorBackground": "#272727d5",
            "menu.selectionBackground": "#00eeff7c",
            "menubar.selectionBackground": "#0dc7d4bd",

            // 选项卡
            "editorGroupHeader.tabsBackground": "#161617",        // 标题栏未使用的地方
            "tab.inactiveBackground": "#161617",                  // 非活动选项卡背景颜色
            "tab.inactiveForeground": "#66666a",                  // 非活动选项卡文字颜色
            "tab.hoverBackground": "#222226",                     // 鼠标悬停在标题上的颜色
            "tab.hoverBorder": "#50e3ee",

            "tab.border": "#38383a",                              // 选项卡间隔线
            "tab.activeBorder": "#50e3ee",                        // 活动选项卡底部边框
            "tab.activeBackground": "#222226",                    // 活动选项卡背景颜色        
            "tab.activeForeground": "#50e3ee",                    // 活动选项卡文字颜色

            "editorHint.foreground": "#fd01f1",                        // 未知波浪线的颜色!?

            // 终端窗口
            "terminal.foreground": "#dddddf",
            "terminal.background": "#111112",
            "terminalCursor.background": "#ffffff",
            "terminalCursor.foreground": "#37adb6",
            "terminal.ansiBrightYellow": "#6cf1d0",

            // 输出栏
            "panelTitle.inactiveForeground": "#99999a",
            "panelTitle.activeForeground": "#50e3ee",
            "panel.background": "#1b1b1c",
            "panel.border": "#8f8f9d",                            // 输出栏分割线

            // 状态栏(最底部)
            "statusBar.background": "#3a3a3e",
            "statusBar.noFolderBackground": "#3a3a3e",
            "statusBar.foreground": "#ceced1",
            "statusBarItem.hoverBackground": "#272731ee",

            // debug状态栏
            "statusBar.debuggingBackground": "#326da3",
            "statusBar.debuggingForeground": "#bef0fde1",
            // debug悬浮窗
            "debugToolBar.background": "#242425",
            "debugToolBar.border": "#2b2b2d",
            // debug当前行
            "editor.stackFrameHighlightBackground": "#13273a93",

            // 滚动条
            "scrollbarSlider.background": "#bebebe1c",
            "scrollbarSlider.hoverBackground": "#dfdfdf2f",
            "scrollbarSlider.activeBackground": "#00eeffa6",

            // 速览窗口(如按Ctrl点头文件时的预览)
            "peekViewEditor.background": "#201f2994",
            "peekViewEditor.matchHighlightBackground": "#0c99ebad",
            "peekViewEditor.matchHighlightBorder": "#4fe3ee",
            "peekViewResult.matchHighlightBackground": "#0c99eb8a",

            "peekViewResult.background": "#1d1d1f",
            "peekView.border": "#66666c",


            // 搜索
            "input.background": "#242426",
            "input.border": "#636367",                                                          // 深水蓝 255e85
            "input.foreground": "#dbdbdd",
            "input.placeholderForeground": "#626264",
            "focusBorder": "#50e3eea8",
            "editor.findMatchBackground": "#3c72afad",
            "editor.findMatchBorder": "#56ffff",
            "editor.findMatchHighlightBackground": "#6e737438",
            "editor.findMatchHighlightBorder": "#9ccfeb",

            // 阴影
            "scrollbar.shadow": "#141415",
            "widget.shadow": "#141415",

            // 括号匹配
            "editorBracketMatch.background": "#23a2c934",
            "editorBracketMatch.border": "#98c6e2",

            // 波浪线
            "editorError.foreground": "#cc4343",
        },
    },
    // "better-comments.highlightPlainText": true,
    "editor.tokenColorCustomizations":
    {
        "[Default Dark+]":
        {
            "strings": "#f0636a",
            "keywords": "#7fd7fa",
            // "functions": "#6ee6df",

            "textMateRules": [

                {
                    "scope": [
                        "meta.preprocessor",            // 预处理器
                    ],
                    "settings": {
                        "foreground": "#4f99e2",
                        // "foreground": "#4f99df",
                        "fontStyle": ""
                    }
                },



                {
                    "scope": [
                        "comment.line",                 // 行注释
                        "comment.block",
                        "comment.block.documentation",
                        "comment",
                    ],
                    "settings": {
                        "foreground": "#607183"
                    }
                },



                {
                    "scope": [
                        "punctuation.separator",
                        "meta.type",
                        "storage.type",
                        "entity",
                        "meta.return-type",
                        // "variable.language", // 貌似是python self关键字
                        "markup.list.numbered",
                        "meta.tag",
                        "meta.selector",
                        "meta.return-type",
                        "entity.other.attribute-name",
                        "entity.other",
                        "entity.name.method",

                    ],
                    "settings": {
                        "foreground": "#ea05ff",
                        "fontStyle": ""
                    }
                },



                {
                    "scope": [
                        "constant.numeric",
                    ],
                    "settings": {
                        "foreground": "#f0636a",
                        "fontStyle": ""
                    }
                },



                {
                    "scope": [
                        "variable.other",
                    ],
                    "settings": {
                        "foreground": "#abd8f1",
                        "fontStyle": ""
                    }
                },




                {
                    "scope": [
                        "storage.modifier",              /* static、const等 */
                        "storage.type",                  /* void,变量类型限定符 */
                        "punctuation.terminator",        /* 分号 */
                        "punctuation.separator",         /* 逗号 */
                        "keyword",
                        "keyword.control",
                        "keyword.operator",                 // 其他操作符(移位等)
                        "keyword.operator.arithmetic",      // 数学操作符(+-*/)
                        "keyword.operator.assignment",      // 赋值操作符(=)
                        "keyword.operator.logical",          // 逻辑操作符(与或非)
                        "keyword.operator.new",
                        "keyword.other",
                        "variable.language",       // 貌似是python self关键字
                        "support.type",         // python except的类型名、python 内置的list、dict类型名
                        // "meta.function-call",             // 函数调用(包括函数名、圆括号、参数列表都是这个颜色)
                    ],
                    "settings": {
                        "foreground": "#7fd7fa"
                    }
                },



                {
                    "scope": [
                        "entity.name.type",             // 类名
                        "entity.name.function",         // 函数名
                        "entity.other.inherited-class", // python 继承于类的名字
                    ],
                    "settings": {
                        "foreground": "#6ee6df"
                    }
                },



                {
                    "scope": [
                        "variable.parameter",             // 参数
                    ],
                    "settings": {
                        "foreground": "#c9f8fc"
                    }
                },



                {
                    "scope": [
                        "constant.character.escape",            // 转义符
                        "constant.character",   // python里面字符串中的{}
                    ],
                    "settings": {
                        "foreground": "#e6c97b",
                        "fontStyle": ""
                    }
                },
            ],
        },
    },

    "editor.insertSpaces": false,
    "editor.renderWhitespace": "none",
    "window.menuBarVisibility": "default",
    "workbench.sideBar.location": "left",
    "workbench.statusBar.visible": true,
    "zenMode.hideLineNumbers": false,
    "workbench.statusBar.feedback.visible": false,
    "workbench.iconTheme": "vscode-icons",
    "editor.maxTokenizationLineLength": 16384,
    "editor.minimap.enabled": false,

    // "editor.fontFamily": "MONACO, 'Courier New', monospace",  // 字体
    "editor.fontFamily": "Consolas, 'Courier New', monospace",
    "editor.cursorBlinking": "smooth",
    "terminal.integrated.cursorBlinking": true, // 字体
}

插件篇

首先肯定安装的是C/C++的插件,之后为了美观,又安装了一个图标插件:vscode-icons.

后来突然发现VSCode支持Markdwon!彻底折服于VSCode的强大了.于是安装了Markdown All in one和Markdown Math这两个Markdown相关的插件.前者应该是用来优化Markdown的使用环境的,后者使VSCode支持输入数学公式.

2020.4.26 更新:VSCode的Markdown渲染和导出毕竟比不上专业的Markd编辑器,所以最后还是换回了Typora.而且导出PDF的插件有问题,每保存一次就重新导出一个PDF,导致VSC变得极其卡顿,一怒之下卸载了,辣鸡拓展.

后来安装了一个背景图插件:background.实测效果还可以,目前一直在用.

在Kevin大佬的推荐下,当初还装了一个Wakatime插件,可以在网页端看到使用一周内VSCode的时间,在各个后缀名文件上的编辑时间等.配置稍微繁琐一些,需要绑定账号,想安装的推荐去网上查配置教程.

自己又装了一个摸鱼的插件:z-reader,可以在VSCode里看电子书...还支持Epub格式,有一些小bug,但是体验还可以.

目前使用的插件大概就这些.

代码片段篇

一开始得知VSCode不支持缺省源还是挺失望的,但是后来打听到了有代码片段这个神奇的东西.可以通过打出设置好的几个字符,然后按回车,就可以直接出现预置好的代码片段,而且可以指定鼠标的位置,简直不能更强大.

于是又经过一番折腾形成了下面的C++代码片段.本来是打算扔一些板子进去的,后来想想板子还是手打比较好.于是只放了缺省源和一些常用的小函数进去.这部分也会一直更新(最后更新于2020.4.26).

{
    "Use for OI or ACM": {
        "prefix": "OI",
        "body": [
            "#include<cstring>",
            "#include<cstdio>",
            "#include<iostream>",
            "#include<algorithm>",
            "#include<vector>",
            "#include<cmath>",
            "#include<map>",
            "#define l(x) (x<<1)",
            "#define r(x) ((x<<1)+1)",
            "#define IL inline",
            "#define reg register",
            "#define LL long long",
            "#define INF 0x3f3f3f3f",
            "using namespace std;",
            "",
            "IL int Abs(int x){return (x<0)?-x:x;}",
            "IL void Swap(int &a,int &b){a^=b^=a^=b;}",
            "IL int Min(int a,int b){return (a<b)?a:b;}",
            "IL int Max(int a,int b){return (a>b)?a:b;}",
            "",
            "IL int read(){",
            "   int p=0,f=1;    char    c=getchar();",
            "   while (c<48||c>57)  {if (c=='-')    f=-1;   c=getchar();}",
            "   while (c>=48&&c<=57)    p=(p<<1)+(p<<3)+c-48,c=getchar();",
            "   return p*f;",
            "}",
            "",
            "int main(){",
            "   #ifdef __Marvolo",
            "   freopen(\"zht.in\",\"r\",stdin);",
            "   freopen(\"zht.out\",\"w\",stdout);",
            "   #endif",
            "   0",
            "   return 0;",
            "}",
        ],
        "description": "OI Board",
    },

    "Struct":{
        "prefix": "datas",
        "body": [
            "struct Data{",
            "   int x,y;",
            "}0;",
        ],
        "description": "A struct with int x,y",
    },

    "Sort Function":{
        "prefix": "sortf",
        "body": [
            "0inline bool cmp(const Data &a,const Data &b){return a.x<b.x;}",
        ],
        "description": "cmp function for struct",
    },

    "Segment Tree":{
        "prefix": "segs",
        "body": [
            "struct Tree{",
            "   int l,r,d,lz;",
            "}t[N*4];0"
        ],
        "description": "struct for segment tree",
    },

    "Flow Struct":{
        "prefix": "flows",
        "body": [
            "struct Flow{",
            "   int t,next,fl,re;",
            "}e[N*8];0"
        ],
        "description": "struct for segment tree",
    },

    "Map Struct":{
        "prefix": "maps",
        "body": [
            "struct Edge{",
            "   int t,next,l;",
            "}e[N*8];0"
        ],
        "description": "struct for map",
    },

    "Add Directed Edge In A Map":{
        "prefix": "mapadd",
        "body": [
            "inline void Add(int s,int t,int l){",
            "   e[lsum].t=t;    e[lsum].l=l;    e[lsum].next=head[s];   head[s]=lsum++;",
            "}0"
        ],
        "description": "Add a directed edge",
    },

    "Flow Add Edge":{
        "prefix": "flowadd",
        "body": [
            "inline void Add(int s,int t,int fl){",
            "   e[lsum].t=t;    e[lsum].fl=fl;  e[lsum].next=head[s];   e[lsum].re=lsum+1;  head[s]=lsum++;",
            "   e[lsum].t=s;    e[lsum].fl=0;   e[lsum].next=head[t];   e[lsum].re=lsum-1;  head[t]=lsum++;"
            "}0"
        ],
        "description": "Add flow edges",
    },

    "Cost-flow Add Edge":{
        "prefix": "costadd",
        "body": [
            "inline void Add(int s,int t,int fl,int cost){",
            "   e[lsum].t=t;    e[lsum].re=lsum+1;  e[lsum].fl=fl;  e[lsum].c=cost;",
            "   e[lsum].from=s; e[lsum].next=head[s];   head[s]=lsum++;",
            "   e[lsum].t=s;    e[lsum].re=lsum-1;  e[lsum].c=-cost;",
            "   e[lsum].from=t; e[lsum].next=head[t];   head[t]=lsum++;",
            "}0",
        ],
        "description": "Add cost-flow edges",
    },

    "Memset the Array":{
        "prefix": "me",
        "body": [
            "memset(1,2,sizeof(0));",
        ],
        "description": "Memset the array",
    },

    "Quick For":{
        "prefix": "fin",
        "body": [
            "for (i=1;i<=n;i++)0",
        ],
        "description": "Print a for quickly",
    },

    "Quick Cul":{
        "prefix": "ksm",
        "body": [
            "inline LL Mi(LL x,LL y){",
            "   LL p=x,t=1,Res=1;",
            "   for (;t<=y;(t&y)?Res=(Res*p)%MOD:0,p=(p*p)%MOD,t<<=1);",
            "   return Res;",
            "}0",
        ],
        "description": "Print function Mi",
    },

    "Open the File":{
        "prefix": "fre",
        "body": [
            "freopen(\"zht.in\",\"r\",stdin);",
            "freopen(\"zht.out\",\"w\",stdout);0",
        ],
        "description": "Print freopen quickly",
    },

    "Open O3":{
        "prefix": "O3",
        "body": [
            "#pragma GCC optimize(3)0",
        ],
        "description": "open O3 quickly",
    },

    "Calculate Time":{
        "prefix": "times",
        "body": [
            "#ifdef __Marvolo",
            "clock_t Start=clock();",
            "#endif",
        ],
        "description": "Begin to calculate time",
    },

    "Calculate Time 2":{
        "prefix": "timee",
        "body": [
            "#ifdef __Marvolo",
            "clock_t End=clock();",
            "cout<<double(End-Start)/1000<<endl;",
            "#endif",
        ],
        "description": "Begin to calculate time",
    },
}

至此VSCode的配置就算告一段落了.以后有新内容(比如插件和代码片段)会继续更新.

说点什么
支持Markdown语法
好耶,沙发还空着ヾ(≧▽≦*)o
Loading...