neovim + clang-format 修改缩进为 4

neovim + clang-format 修改缩进为 4

写在前面 使用lazyvim时,搭配clang-format格式化代码,会将代码的缩进改为 2 spaces,因为习惯 4 spaces 缩进,遂改之。 1. 补充options.lua vim ~/.config/nvim/lua/options.lua 添加以下内容: local opt = v

写在前面

使用lazyvim时,搭配clang-format格式化代码,会将代码的缩进改为 2 spaces,因为习惯 4 spaces 缩进,遂改之。


1. 补充options.lua

vim ~/.config/nvim/lua/options.lua

添加以下内容:

local opt = vim.opt

opt.shiftwidth = 4 -- Size of an indent
opt.tabstop = 4 -- Number of spaces tabs count for

2. 修改stylua.toml

vim ~/.config/nvim/stylua.toml

修改以下内容:

indent_type = "Spaces"
indent_width = 4

3. 在项目根目录添加文件

新建.clang-format

添加以下内容:

---
BasedOnStyle: llvm
IndentWidth: 4

# 不要给头文件排序
SortIncludes: false
# 列的最大长度是 260
ColumnLimit: 120

Comment