Neovim lua config : New tab size isn't applied in C++ files

Viewed 2286

I'm configuring Neovim 0.5 using Lua. I set the tab size to 4 in init.lua, and it works. But in C++ files, the tab size is 8, and I have to execute :set shiftwidth=4, :set tabstop=4 and :set expandtab manually. Here are the config files :

init.lua:

require "plugins"
require "theme"

local g = vim.g
local wo = vim.wo
local bo = vim.bo

local TAB_WIDTH = 4
bo.tabstop = TAB_WIDTH
bo.shiftwidth = TAB_WIDTH
bo.expandtab = true

wo.cursorline = true
wo.nu = true
wo.rnu = true

lua/plugins.lua:

require "paq" {
        "savq/paq-nvim";

        "neovim/nvim-lspconfig";
        "Shatur/neovim-ayu";
}

lua/theme.lua:

vim.g.ayu_mirage = true

vim.cmd("colo ayu")

Maybe a plugin that overrides config for C++ files ?

1 Answers

of course its not working

bo.tabstop = TAB_WIDTH
bo.shiftwidth = TAB_WIDTH
bo.expandtab = true

bo is a buffer specific vim variable.

when you call the above code from init.lua vim doesnt know to which buffer to apply these settings, because you dont mention what buffer you want the settings to apply to.

wait ... and second (which is most important)

  • expandtab
  • shiftwidth
  • tabstop

are not buffer or window options, they are from vim.opt

here is my init.lua config (and its working)

local set = vim.opt -- set options
set.tabstop = 4
set.softtabstop = 4
set.shiftwidth = 4
Related