DAY20 Optimizing VS Code for C/C++ Development on Ubuntu

Optimizing VS Code for C/C++ Development on Ubuntu

This article documents an optimized Visual Studio Code setup for C and C++ development on Ubuntu 22.04.

It includes formatter integrations, IntelliSense configuration, CMake workflow improvements, UI settings, and tips for smoother embedded development.

1. Introduction

VS Code is one of the most flexible editors for C and C++ development, especially when working on Linux or embedded systems.

With the right configuration, you can achieve:

  • Fast and accurate code completion (via clangd)
  • Consistent formatting (via clang-format)
  • Better CMake integration
  • Improved navigation using ctags
  • Cleaner UI and automatic file saving
  • Support for DeviceTree, Kconfig, Makefiles, and more

This post explains each configuration section and how it improves your workflow.


2. Formatter Configuration (clang-format)

The settings configure VS Code to automatically format C/C++ files using xaver.clang-format:

json 复制代码
"[c]": {
    "editor.defaultFormatter": "xaver.clang-format"
},
"[cpp]": {
    "editor.defaultFormatter": "xaver.clang-format"
},
"editor.formatOnSave": true

Why this helps

  • Ensures consistent code style across the project
  • Avoids messy diffs when committing to Git
  • Automatically aligns braces, indentation, and spacing

You can also adjust the formatting style with:

json 复制代码
"C_Cpp.clang_format_style": "Visual Studio"

For better consistency, changing this to "LLVM" or "Google" is recommended.


3. clangd Configuration (Recommended C/C++ language server)

A custom clangd binary is used:

json 复制代码
"clangd.path": "/home/linux/clangd_14.0.3/bin/clangd",
"clangd.arguments": [
    "--log=verbose",
    "--clang-tidy",
    "--background-index",
    "--inlay-hints=false"
]

What these features do

Feature Description
--clang-tidy Static analysis and code quality checks
--background-index Builds project index silently for faster navigation
--inlay-hints=false Disables inline hint clutter
--log=verbose Useful when debugging clangd issues

You also disabled Microsoft's IntelliSense engine:

json 复制代码
"C_Cpp.intelliSenseEngine": "disabled"

This ensures that clangd is the only backend providing completions---faster and more accurate.


4. CMake Workflow Optimization

json 复制代码
"cmake.options.statusBarVisibility": "visible",
"makefile.configureOnOpen": true,
"cmake.pinnedCommands": [
    "workbench.action.tasks.configureTaskRunner",
    "workbench.action.tasks.runTask"
]

Improvements

  • CMake status bar is always visible
  • Automatically configure Makefile projects when opening
  • Quick access to commonly used build/run commands

This setup is especially helpful in embedded projects running cross-compiled toolchains.


5. UI Enhancements

The settings apply a modern UI theme:

json 复制代码
"workbench.iconTheme": "vscode-icons",
"workbench.colorTheme": "One Monokai",
"workbench.preferredDarkColorTheme": "One Dark Pro"

And a clean development font:

json 复制代码
"editor.fontFamily": "JetBrains Mono, 'Courier New', monospace",
"editor.fontLigatures": true,
"editor.fontSize": 18

Why this matters

  • Ligature fonts improve readability for syntax-heavy languages like C++
  • Larger font reduces eye strain during long development sessions
  • Icons help distinguish file types clearly

6. Hex Editor Integration

json 复制代码
"workbench.editorAssociations": {
    "*.o": "hexEditor.hexedit"
}

This is extremely useful in:

  • Embedded firmware reverse engineering
  • Reading binary logs
  • Inspecting compiled ELF sections

Additional hex editor configuration:

json 复制代码
"hexeditor.columnWidth": 16,
"hexeditor.showDecodedText": true,
"hexeditor.defaultEndianness": "little"

7. ctags Indexing

json 复制代码
"ctags.regenerateOnSave": true,
"ctags.languages": ["C", "C++", "DTS", "Kconfig", "Make"]

Why this helps

  • Ultra-fast symbol search
  • Works even when clangd analysis is not available
  • Supports DeviceTree and Linux kernel environments

8. Embedded Linux / DeviceTree Support

json 复制代码
"devicetree.bindings": [
    "/home/linux/nfs/imx6/linux-imx-rel_imx_4.1.15_2.1.0_ga_alientek/Documentation/devicetree/bindings"
]

This enables:

  • Hover hints for DTS nodes
  • Validation of DeviceTree bindings
  • Faster debugging of ARM/SoC kernel configurations

Essential for i.MX6 / ARM-based embedded work.


9. Automatic Saving

json 复制代码
"files.autoSave": "afterDelay"

Useful when switching between Vim/terminal builds and VS Code.


10. Final Thoughts

The configuration shown here turns VS Code into a powerful C/C++ IDE on Ubuntu, suitable for:

  • Embedded Linux development
  • Kernel-level C work
  • CMake-based or Makefile-based projects
  • Bare-metal or cross-compiled toolchains
  • Modern C++ projects using clangd

I

相关推荐
Linux技术芯9 分钟前
浅谈nvme驱动中的nvme_alloc_ns函数的实现原理和底层逻辑
linux
AOwhisky23 分钟前
Linux防火墙管理指南
linux·运维·服务器
礼拜天没时间.24 分钟前
Linux 系统规范配置:建立标准目录结构、 repo 源获取、修改终端变色
linux·服务器·centos·repo·终端变色
一只专注api接口开发的技术猿24 分钟前
如何处理淘宝 API 的请求限流与数据缓存策略
java·大数据·开发语言·数据库·spring
superman超哥25 分钟前
Rust 异步递归的解决方案
开发语言·后端·rust·编程语言·rust异步递归
期待のcode26 分钟前
Java虚拟机的非堆内存
java·开发语言·jvm
黎雁·泠崖27 分钟前
Java入门篇之吃透基础语法(二):变量全解析(进制+数据类型+键盘录入)
java·开发语言·intellij-idea·intellij idea
老歌老听老掉牙33 分钟前
优化样条曲线拟合参数解决三维建模中的截面连续性问题
c++·opencascade·样条曲线
liqb36540 分钟前
RUN_TO_PARITY特性对调度延时的影响
linux