Use Visual Studio Code

My Visual Studio Code (VSC) usage.

Installation

Download VSC from the official website, and install it with its tips.

Custom Settings

Fira Code is a free monospaced font with programming ligatures.
ref: https://github.com/tonsky/FiraCode/wiki/VS-Code-Instructions

Extensions

Settings Sync

Outdated. It is integrated to VSC.
ref: https://code.visualstudio.com/docs/editor/settings-sync

Material Theme

Material Theme is the official material theme for VSC, while Community Material Theme is a theme maintained by the community with ‘legacy’ color schemes. Material Icon Theme, which provides Material Design Icons for VSC, has far more installers than Material Theme Icons. According to my user experience, Material Icon Theme is also faster.

Background

background can bring background images to your VSC.

Markdown Preview Enhanced

Markdown Preview Enhanced is an extension to write markdown on VSC. ctrl+k, ctrl+v to see the preview. Visit its official website to realize how to use.

Marp for VS Code

Marp for VS Code is a useful extension for making slides in markdown. It can transform md to html, pdf and pptx.

ctrl+alt+win+n (Windows) to start writing a slide deck quickly.

1
2
3
4
5
---
marp: true
---

# Your slide deck

Code Runner

Code Runner is a easy way to run code snippet or code file for multiple languages: C, C++, Java, JavaScript, PHP, Python, and so on.

Build C/C++ Environment

This chapter introduces how to build a C/C++ environment on VSC on Windows.

Steps:

  1. Download C/C++ Extension. Open VSC, click Extensions (扩展), or use shortcut ctrl+shift+x. Search C/C++ and download it. To use Simplified Chinese UI, you can install Chinese (Simplified) (简体中文) Language Pack for Visual Studio Code.
  2. Install MinGW-w64. Install it from the official website of MinGW-w64, or its sourceforge page. Notice: don’t install MinGW.
  3. Change environment virable. If you use win10 or win11, search “env” (环境变量), click Edit the System Environment Variables (编辑系统环境变量), click Advanced (高级) -> Environment Virables... (环境变量), click Path (路径), click new, add the path C:\MInGW\bin\ (change it accroding to your path). Run gcc -v on cmd to know whether you are successful.
  4. Create a C/C++ file. e.g., main.cpp, write some words in it, an example:
    1
    2
    3
    4
    5
    6
    #include <iostream>
    using namespace std;
    int main() {
    cout<<"hello world"<<endl;
    return 0;
    }
  5. Create tasks.json. Click Terminal (终端) -> Configure Tasks..., click g++.exe. Now, select main.cpp, click Terminal -> Run Task, click C/C++: g++.exe build active file. Then a internal terminal will open to show the build result. If successfully, it will create main.exe.
  6. Create lauch.json. Click Run (运行) -> Add Configuration....
  7. Now, F5 can start debugging.

Further reading:

Simple ACM

If you are a ACMer, Competitive Coding Helper is a good extension to test your code.

If you write codes in your computer, you can click settings->用户代码片段, create cpp.json, which will efficiently save your time. my cpp.json is as follows,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
{
"cdf": {
"prefix": "cdf",
"body": [
"#include<bits/stdc++.h>",
"#define iof std::ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)",
"#define rd(n) cin>>n",
"#define rd2(a,b) cin>>a>>b",
"#define rdn(ar,a,n) rep(i,a,n) cin>>ar[i];",
"#define prt(n) cout<<n<<el",
"#define dbg(n) cout<<#n<<'='<<n<<el",
"#define dbgn(ar,a,n) cout<<#ar<<'=';rep(i,a,n) cout<<ar[i]<< ' ';cout<<el",
"#define rep(i,a,b) for (int i=a;i<(int)b;i++)",
"#define per(i,a,b) for (int i=(int)b;i>=a;i--)",
"#define str string",
"#define pii pair<int, int>",
"#define mm memset",
"#define elif else if",
"#define mkp make_pair",
"#define pb push_back",
"#define fi first",
"#define se second",
"#define inf 0x3f3f3f3f",
"#define el '\\n'",
"#define endl '\\n'",
"typedef long long ll;",
"typedef long double ld;",
"using namespace std;",
"const int mod=1e9+7;",
"const int N=1e5+1;",
"\n\nvoid solve()\n{\n\tint n;\n\trd(n);\n\t$0\n}",
"\nint main() {\n\tiof;",
"\tint t;\n\trd(t);\n\twhile(t--) solve();",
"\treturn 0;\n}",
],
"description": "init codeforce model"
},
"file": {
"prefix": "filein",
"body": [
"#ifndef ONLINE_JUDGE",
"freopen(\"in.txt\",\"r\",stdin);",
"#endif",
],
"description": "filein"
}
}

Then prt(n) can replace cout<<n<<'\n', rep(i,a,b) can replace for(int i=a;i<b;i++), and so on. Specifically, I establish a structure of while(t--) solve() to adapt to the testcases of codeforces. Type cdf and Enter, it will add above codes to your .cpp file.

Clang-Format

Use Everything to find clang-format.exe, then ./clang-format -style=LLVM -dump-config > .clang-format can generate a .clang-format file. The style can be LLVM, Google, Chromium, Mozilla, WebKit.

ref: zhihu: VS Code+Clang-format格式化代码

References

  • 《Visual Studio Code权威指南》