From 4b6c92176895c92e77c1bbde8163e80823b01436 Mon Sep 17 00:00:00 2001 From: caem Date: Sun, 26 May 2024 11:43:53 +0200 Subject: [PATCH] Use ftplugin instead of autocmds to set indent The autocmds approach had the issue of overwriting the indentation globally for all files. So if you opened a .nix file and then wanted to edit a .c file, it would then still do 2 space indentation when it should be 4. The autocmds approach was redundant in the first place as the ftplugin directory already exists for this exact purpose and does it without the aformentioned issue. --- users/hu/packages/nvim/config/ftplugin/lua.lua | 3 +++ users/hu/packages/nvim/config/ftplugin/nix.lua | 3 +++ .../hu/packages/nvim/config/lua/settings/autocmds.lua | 10 ---------- 3 files changed, 6 insertions(+), 10 deletions(-) create mode 100644 users/hu/packages/nvim/config/ftplugin/lua.lua create mode 100644 users/hu/packages/nvim/config/ftplugin/nix.lua diff --git a/users/hu/packages/nvim/config/ftplugin/lua.lua b/users/hu/packages/nvim/config/ftplugin/lua.lua new file mode 100644 index 0000000..4f74ce9 --- /dev/null +++ b/users/hu/packages/nvim/config/ftplugin/lua.lua @@ -0,0 +1,3 @@ +vim.bo.tabstop = 2 +vim.bo.softtabstop = 2 +vim.bo.shiftwidth = 2 diff --git a/users/hu/packages/nvim/config/ftplugin/nix.lua b/users/hu/packages/nvim/config/ftplugin/nix.lua new file mode 100644 index 0000000..4f74ce9 --- /dev/null +++ b/users/hu/packages/nvim/config/ftplugin/nix.lua @@ -0,0 +1,3 @@ +vim.bo.tabstop = 2 +vim.bo.softtabstop = 2 +vim.bo.shiftwidth = 2 diff --git a/users/hu/packages/nvim/config/lua/settings/autocmds.lua b/users/hu/packages/nvim/config/lua/settings/autocmds.lua index 8edc7f9..e69de29 100644 --- a/users/hu/packages/nvim/config/lua/settings/autocmds.lua +++ b/users/hu/packages/nvim/config/lua/settings/autocmds.lua @@ -1,10 +0,0 @@ --- 2 indentation languages -vim.api.nvim_create_autocmd({"BufEnter", "BufWinEnter"}, { - pattern = {"*.lua", "*.nix"}, - callback = function() - vim.opt.tabstop = 2 - vim.opt.softtabstop = 2 - vim.opt.shiftwidth = 2 - end -}) -