VScode - ubuntu - C/C++開發(fā)環(huán)境

安裝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”

image-20210922230743603.png

填入120低匙,表示120個字符。下圖右邊為垂直標(biāo)尺碳锈。

image-20210922230825154.png

格式化文件

可自定義代碼格式顽冶,并將名為“.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“

image-20211010160827118.png

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)址

image-20210922225826558.png

參考

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末淳玩,一起剝皮案震驚了整個濱河市非竿,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌承匣,老刑警劉巖锤悄,帶你破解...
    沈念sama閱讀 222,729評論 6 517
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異零聚,居然都是意外死亡,警方通過查閱死者的電腦和手機政模,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,226評論 3 399
  • 文/潘曉璐 我一進店門蚂会,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人趁猴,你說我怎么就攤上這事彪见《愕穑” “怎么了企巢?”我有些...
    開封第一講書人閱讀 169,461評論 0 362
  • 文/不壞的土叔 我叫張陵,是天一觀的道長或听。 經(jīng)常有香客問我,道長誉裆,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 60,135評論 1 300
  • 正文 為了忘掉前任粱腻,我火速辦了婚禮斩跌,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘耀鸦。我一直安慰自己,他們只是感情好袖订,可當(dāng)我...
    茶點故事閱讀 69,130評論 6 398
  • 文/花漫 我一把揭開白布洛姑。 她就那樣靜靜地躺著,像睡著了一般楞艾。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 52,736評論 1 312
  • 那天蜀细,我揣著相機與錄音,去河邊找鬼谆刨。 笑死归斤,一個胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的脏里。 我是一名探鬼主播,決...
    沈念sama閱讀 41,179評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼番舆,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了疏哗?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 40,124評論 0 277
  • 序言:老撾萬榮一對情侶失蹤返奉,失蹤者是張志新(化名)和其女友劉穎吗氏,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體哮针,經(jīng)...
    沈念sama閱讀 46,657評論 1 320
  • 正文 獨居荒郊野嶺守林人離奇死亡坦袍,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,723評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了蛮放。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片奠宜。...
    茶點故事閱讀 40,872評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖娩嚼,靈堂內(nèi)的尸體忽然破棺而出滴肿,到底是詐尸還是另有隱情岳悟,我是刑警寧澤泼差,帶...
    沈念sama閱讀 36,533評論 5 351
  • 正文 年R本政府宣布堆缘,位于F島的核電站滔灶,受9級特大地震影響吼肥,放射性物質(zhì)發(fā)生泄漏麻车。R本人自食惡果不足惜萄涯,卻給世界環(huán)境...
    茶點故事閱讀 42,213評論 3 336
  • 文/蒙蒙 一涝影、第九天 我趴在偏房一處隱蔽的房頂上張望枣察。 院中可真熱鬧燃逻,春花似錦、人聲如沸猿涨。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,700評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽稽揭。三九已至,卻和暖如春事镣,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背璃哟。 一陣腳步聲響...
    開封第一講書人閱讀 33,819評論 1 274
  • 我被黑心中介騙來泰國打工喊递, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人铐伴。 一個月前我還...
    沈念sama閱讀 49,304評論 3 379
  • 正文 我出身青樓调鲸,卻偏偏與公主長得像挽荡,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子定拟,可洞房花燭夜當(dāng)晚...
    茶點故事閱讀 45,876評論 2 361

推薦閱讀更多精彩內(nèi)容