安裝VS Code
https://code.visualstudio.com/
sudo dpkg -i code_xxxx_amd64.deb
安裝插件
vscode-icons | 圖標(biāo)插件,資源管理器下各個(gè)文件夾的圖標(biāo) |
compareit | 比較插件,可以用于比較兩個(gè)文件的差異 |
C/C++ | The C/C++ extension adds language support for C/C++ to Visual Studio Code, including features such as IntelliSense and debugging. |
C/C++ Themes | UI Themes for C/C++ extension |
Better C++ Syntax | The bleeding edge of the C++ syntax |
C/C++ Snippets | C/C++重用代碼塊 |
C/C++ Advanced Lint | C/C++靜態(tài)檢測(cè) |
Include AutoComplete | 頭文件智能補(bǔ)全 |
Path Intellisense | 文件路徑智能補(bǔ)全 |
ARM | 支持 ARM 匯編語(yǔ)法高亮顯示 |
DeviceTree | 設(shè)備樹(shù)語(yǔ)法插件 |
C/C++ GNU Global | Provide Intellisense for C/C++ using GNU Global |
C++ Intellisense | C/C++ Intellisense with the help of GNU Global tags |
CMake | CMake langage support |
CMake Tools | Extended CMake support |
Code Runner | 代碼運(yùn)行,僅用于Demo,正式工程應(yīng)用CMake |
Doxygen Documentation Generator | 自動(dòng)生成Doxygen格式注釋 |
Remote - SSH | Open any folder on a remote machine using SSH and take advantage of VS Code's full feature set. |
Remote - WSL | Open any folder in the Windows Subsystem for Linux (WSL) and take advantage of Visual Studio Code's full feature set. |
Remote - Containers | Open any folder or repository inside a Docker container and take advantage of Visual Studio Code's full feature set. |
highlight-words | 高亮選中的單詞或表達(dá)式,需手動(dòng)設(shè)置快捷鍵,比如設(shè)置成“Ctrl + F8” |
Bracket Pair Colorizer | A customizable extension for colorizing matching brackets |
TODO Highlight | Highlight TODO, FIXME and other annotations within your code. |
Todo Tree | Show TODO, FIXME, etc. comment tags in a tree view |
Bookmarks | Mark lines and jump to them |
GNU Global
sudo apt install global
# 在工程目錄執(zhí)行以便建立索引
gtags -v
# 增量更新索引
gtags -vi
# 查找函數(shù)或變量的定義和申明
global -x <variable name or function name>
# 查找函數(shù)或變量的引用
global -xr <variable name or function name>
生成三個(gè)文,GTAGS是定義的數(shù)據(jù)庫(kù),GRTAGS是引用的數(shù)據(jù)庫(kù),GPATH是路徑的數(shù)據(jù)庫(kù)
右鍵即可使用Go to Definition、Peak Definition、Find All References
Lint
sudo apt install clang
sudo apt install cppcheck
違反語(yǔ)言規(guī)則或則檢查規(guī)則,將在違規(guī)處顯示告警信息,能顯著減少編譯時(shí)間,提高效率。
CMake
sudo apt install cmake
# 創(chuàng)建CMake工程
CMake:Quick Start
# 常用功能
CMake:Configure
CMake:Build
CMake:Clean
CMake:Run
CMake:Debug
CMake:Install
C/C++
如下配置用于研究linux kernel,其他工程也類似
Ctrl + Shift + P >> “C/C++:Edit configurations…(json)”
自動(dòng)生成“.vscode/c_cpp_properties.json”,在“includePath”中增加頭文件路徑
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include/**",
"${workspaceFolder}/include/linux/**",
"${workspaceFolder}/arch/arm64/**",
"${workspaceFolder}/arch/arm64/include/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Ctrl + Shift + P >> Preferences: Open Workspace Settings (JSON)
自動(dòng)生成“.vscode/settings.json”
{
"search.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true,
"**/drivers": true,
"**/sound": true,
"**/tools": true,
"**/arch/alpha": true,
"**/arch/arc": true,
"**/arch/c6x": true,
"**/arch/h8300": true,
"**/arch/hexagon": true,
"**/arch/ia64": true,
"**/arch/m32r": true,
"**/arch/m68k": true,
"**/arch/microblaze": true,
"**/arch/mn10300": true,
"**/arch/nds32": true,
"**/arch/nios2": true,
"**/arch/parisc": true,
"**/arch/powerpc": true,
"**/arch/s390": true,
"**/arch/sparc": true,
"**/arch/score": true,
"**/arch/sh": true,
"**/arch/um": true,
"**/arch/unicore32": true,
"**/arch/xtensa": true
},
// Configure glob patterns for excluding files and folders.
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true,
"**/drivers": true,
"**/sound": true,
"**/tools": true,
"**/arch/alpha": true,
"**/arch/arc": true,
"**/arch/c6x": true,
"**/arch/h8300": true,
"**/arch/hexagon": true,
"**/arch/ia64": true,
"**/arch/m32r": true,
"**/arch/m68k": true,
"**/arch/microblaze": true,
"**/arch/mn10300": true,
"**/arch/nds32": true,
"**/arch/nios2": true,
"**/arch/parisc": true,
"**/arch/powerpc": true,
"**/arch/s390": true,
"**/arch/sparc": true,
"**/arch/score": true,
"**/arch/sh": true,
"**/arch/um": true,
"**/arch/unicore32": true,
"**/arch/xtensa": true
},
"files.associations": {
"rmap.h": "c",
"bootmem.h": "c",
"processor.h": "c",
"highmem.h": "c",
"memcontrol.h": "c",
"page-flags.h": "c"
}
}
設(shè)置垂直標(biāo)尺
打開(kāi)"settings",所有“editor.rulers”,點(diǎn)擊“settings.json”
填入120,表示120個(gè)字符。下圖右邊為垂直標(biāo)尺。
格式化文件
可自定義代碼格式,并將名為“.clang-format”的格式文件放到VS Code工程根目錄。
sudo apt install clang-format
# 生成llvm風(fēng)格的格式
clang-format -style="{BasedOnStyle: llvm, IndentWidth: 4}" -dump-config > .clang-format
# 生成google風(fēng)格的格式
clang-format -style="{BasedOnStyle: google, IndentWidth: 4}" -dump-config > .clang-format
自定義格式,參考 https://zhuanlan.zhihu.com/p/356143396
快捷鍵:ctrl + shift + I
或則右鍵并選擇Format Document
重命名
選擇需重名的Symbol,右鍵并選擇“Rename Symbol”,輸入New Symbol
按“Shift+Enter”,然后選擇需要修改的代碼,并按“Shift+Enter“
Git
Git History | View git log, file history, compare branches or commits |
GitLens — Git supercharged | Supercharge the Git capabilities built into Visual Studio Code — Visualize code authorship at a glance via Git blame annotations and code lens, seamlessly navigate and explore Git repositories, gain valuable insights via powerful comparison commands, and so much more |
Git Graph | View a Git Graph of your repository, and perform Git actions from the graph. |
在“Source Control”進(jìn)行操作
Remote - SSH
配置和使用請(qǐng)參考:
https://code.visualstudio.com/docs/remote/ssh#_getting-started
公司的辦公環(huán)境一般是window,開(kāi)發(fā)環(huán)境為ubuntu。通過(guò)此插件連接到ubuntu進(jìn)行開(kāi)發(fā),大部分功能是在ubuntu上執(zhí)行,PC僅顯示和編輯代碼。
備注: 連接到Remote Server,須選擇本地的插件安裝到Remote server
代理
由于數(shù)據(jù)安全,大公司會(huì)屏蔽部分外網(wǎng)功能并提供代理服務(wù)。
打開(kāi)“settings”,搜索“proxy”,在“Http:Proxy”中輸入代理網(wǎng)址
參考
- https://code.visualstudio.com/docs
- https://blog.csdn.net/p1279030826/article/details/105340991
- https://my.oschina.net/u/4256916/blog/3311800
- https://www.bilibili.com/video/BV1az411B7hd?from=search&seid=14050932776868743483&spm_id_from=333.337.0.0
- https://blog.csdn.net/qq_43406338/article/details/109397831