From 29a780f9293287ca7bdad40eed3296f10ceedc8b Mon Sep 17 00:00:00 2001 From: Adam French Date: Tue, 20 Oct 2026 13:12:06 +0100 Subject: [PATCH] Use 4-space indent for C/C++ in nvim Drop the 2-space C/C++ override and set IndentWidth: 4 in clangd's fallback style so formatting matches the editor. Co-Authored-By: Claude Opus 5.5 --- nvim/README.md | 2 +- nvim/lua/config/autocmds.lua | 6 +----- nvim/lua/plugins/clangd.lua | 5 +++-- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/nvim/README.md b/nvim/README.md index 9eeb15e..3825881 100644 --- a/nvim/README.md +++ b/nvim/README.md @@ -35,7 +35,7 @@ this file only covers what's different. Press `` and wait for which-key, ## Behaviour changes from LazyVim -- 4-space indent by default; C/C++ uses 2 spaces and has format-on-save **off** +- 4-space indent everywhere (clangd fallback style matches); C/C++ has format-on-save **off** (format manually with `cf`) - `nvim a b c` opens the files side by side - Inactive windows are dimmed (vimade); markdown renders inline (markview) diff --git a/nvim/lua/config/autocmds.lua b/nvim/lua/config/autocmds.lua index 0169103..02a0e40 100644 --- a/nvim/lua/config/autocmds.lua +++ b/nvim/lua/config/autocmds.lua @@ -7,14 +7,10 @@ -- Or remove existing autocmds by their group name (which is prefixed with `lazyvim_` for the defaults) -- e.g. vim.api.nvim_del_augroup_by_name("lazyvim_wrap_spell") --- C/C++ uses 2-space indent to match clang-format's LLVM default +-- Disable LazyVim's format-on-save for C/C++ vim.api.nvim_create_autocmd("FileType", { pattern = { "c", "cpp" }, callback = function() - vim.opt_local.tabstop = 2 - vim.opt_local.shiftwidth = 2 - vim.opt_local.softtabstop = 2 - -- Disable LazyVim's format-on-save for C/C++ vim.b.autoformat = false end, }) diff --git a/nvim/lua/plugins/clangd.lua b/nvim/lua/plugins/clangd.lua index 7a8647d..6cb833f 100644 --- a/nvim/lua/plugins/clangd.lua +++ b/nvim/lua/plugins/clangd.lua @@ -12,8 +12,9 @@ return { "--completion-style=detailed", "--function-arg-placeholders", -- ColumnLimit: 0 = fix indentation only; keep existing line - -- breaks, never rewrap or join lines - "--fallback-style={BasedOnStyle: LLVM, ColumnLimit: 0}", + -- breaks, never rewrap or join lines. IndentWidth: 4 matches + -- the editor's shiftwidth + "--fallback-style={BasedOnStyle: LLVM, IndentWidth: 4, ColumnLimit: 0}", }, }, },