安裝VS Code
https://code.visualstudio.com/
sudo dpkg -i code_xxxx_amd64.deb
安裝插件
vscode-icons | 圖標(biāo)插件,資源管理器下各個文件夾的圖標(biāo) |
compareit | 比較插件彻亲,可以用于比較兩個文件的差異 |
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)檢測 |
Include AutoComplete | 頭文件智能補全 |
Path Intellisense | 文件路徑智能補全 |
ARM | 支持 ARM 匯編語法高亮顯示 |
DeviceTree | 設(shè)備樹語法插件 |
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 | 代碼運行孕锄,僅用于Demo,正式工程應(yīng)用CMake |
Doxygen Documentation Generator | 自動生成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á)式苞尝,需手動設(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>
生成三個文,GTAGS是定義的數(shù)據(jù)庫宙址,GRTAGS是引用的數(shù)據(jù)庫轴脐,GPATH是路徑的數(shù)據(jù)庫
右鍵即可使用Go to Definition、Peak Definition抡砂、Find All References
Lint
sudo apt install clang
sudo apt install cppcheck
違反語言規(guī)則或則檢查規(guī)則豁辉,將在違規(guī)處顯示告警信息,能顯著減少編譯時間舀患,提高效率。
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)”
自動生成“.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)
自動生成“.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)尺
打開"settings",所有“editor.rulers”现使,點擊“settings.json”
填入120低匙,表示120個字符。下圖右邊為垂直標(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”進行操作
Remote - SSH
配置和使用請參考:
https://code.visualstudio.com/docs/remote/ssh#_getting-started
公司的辦公環(huán)境一般是window倘要,開發(fā)環(huán)境為ubuntu十拣。通過此插件連接到ubuntu進行開發(fā)封拧,大部分功能是在ubuntu上執(zhí)行志鹃,PC僅顯示和編輯代碼狰挡。
備注: 連接到Remote Server,須選擇本地的插件安裝到Remote server
代理
由于數(shù)據(jù)安全虏两,大公司會屏蔽部分外網(wǎng)功能并提供代理服務(wù)铛只。
打開“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