From e1ec30f328a881fd67b0d1b17c666c99280a7a9b Mon Sep 17 00:00:00 2001 From: kalmenn Date: Wed, 20 Nov 2024 14:09:13 +0100 Subject: [PATCH 1/2] feat(filetypes): Set nix files to use 2 spaces for indentation --- lua/filetypes.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/filetypes.lua b/lua/filetypes.lua index 7c232a4..06635db 100644 --- a/lua/filetypes.lua +++ b/lua/filetypes.lua @@ -12,5 +12,11 @@ vim.filetype.add({ end, idr = "idris2", wgsl = "wgsl", + nix = function(_, bufnr) + vim.bo[bufnr].shiftwidth = 2 + vim.bo[bufnr].tabstop = 2 + vim.bo[bufnr].expandtab = true + return "nix" + end, }, }) From 818765d45bf64a58f4979199263e46c7f24b1996 Mon Sep 17 00:00:00 2001 From: kalmenn Date: Wed, 20 Nov 2024 14:09:37 +0100 Subject: [PATCH 2/2] feat: Create a user command for switching between tabs indent and spaces --- init.lua | 1 + lua/commands.lua | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 lua/commands.lua diff --git a/init.lua b/init.lua index c174d3c..4b3ce5b 100644 --- a/init.lua +++ b/init.lua @@ -21,5 +21,6 @@ require("lazy").setup({ { import = "plugins" } }) require("sets") require("remaps") require("filetypes") +require("commands") vim.notify("starting nvim 🏕️") diff --git a/lua/commands.lua b/lua/commands.lua new file mode 100644 index 0000000..67fff56 --- /dev/null +++ b/lua/commands.lua @@ -0,0 +1,21 @@ +vim.api.nvim_create_user_command("Tabs", + function(opts) + vim.bo[0].expandtab = false + if (opts.fargs[1] ~= nil) then + vim.bo[0].shiftwidth = tonumber(opts.fargs[1]) + vim.bo[0].tabstop = tonumber(opts.fargs[1]) + end + end, + { nargs = "?" } +) + +vim.api.nvim_create_user_command("NoTabs", + function(opts) + vim.bo[0].expandtab = true + if (opts.fargs[1] ~= nil) then + vim.bo[0].shiftwidth = tonumber(opts.fargs[1]) + vim.bo[0].tabstop = tonumber(opts.fargs[1]) + end + end, + { nargs = "?" } +)