From 5485b784e00bb0d6ec370e471e72a9ff066f5bbb Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 7 Feb 2025 12:50:36 -0500 Subject: [PATCH] add helpful indentation status/changing things to neovim --- nvim/init.lua | 1 + nvim/lua/cmds.lua | 17 +++++++++++++++++ nvim/lua/plugins/lualine.lua | 16 +++++++++++++++- nvim/lua/plugins/vim-sleuth.lua | 1 + 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 nvim/lua/cmds.lua diff --git a/nvim/init.lua b/nvim/init.lua index fdb0484..95a1b82 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -26,6 +26,7 @@ vim.g.have_nerd_font = true require 'options' require 'keymaps' require 'autocmds' +require 'cmds' require 'lazy-bootstrap' require 'lazy-plugins' diff --git a/nvim/lua/cmds.lua b/nvim/lua/cmds.lua new file mode 100644 index 0000000..4598bf5 --- /dev/null +++ b/nvim/lua/cmds.lua @@ -0,0 +1,17 @@ +local function set_indent(use_spaces, size) + vim.o.expandtab = use_spaces + vim.o.shiftwidth = size + vim.o.tabstop = size +end + +vim.api.nvim_create_user_command('IndentTabs', function(opts) + local size = tonumber(opts.fargs[1]) + set_indent(false, size) + print('Set buffer indentation to tabs with indent/tab size of', size) +end, { nargs = 1 }) + +vim.api.nvim_create_user_command('IndentSpaces', function(opts) + local size = tonumber(opts.fargs[1]) + set_indent(true, size) + print('Set buffer indentation to spaces with indent/tab size of', size) +end, { nargs = 1 }) diff --git a/nvim/lua/plugins/lualine.lua b/nvim/lua/plugins/lualine.lua index a269462..fe82fd5 100644 --- a/nvim/lua/plugins/lualine.lua +++ b/nvim/lua/plugins/lualine.lua @@ -5,6 +5,20 @@ return { 'nvim-tree/nvim-web-devicons', }, config = function() + local current_indent = function() + local output = '' + if vim.o.expandtab then + output = output .. 'S' + else + output = output .. 'T' + end + output = output .. ':' .. vim.o.shiftwidth + if vim.o.shiftwidth ~= vim.o.tabstop then + output = output .. ':' .. vim.o.tabstop + end + return output + end + require('lualine').setup { options = { globalstatus = false, @@ -18,7 +32,7 @@ return { lualine_a = { 'mode' }, lualine_b = { 'branch', 'diff', 'diagnostics' }, lualine_c = { { 'filename', path = 2 } }, - lualine_x = { 'encoding', 'fileformat', 'filetype' }, + lualine_x = { 'encoding', 'fileformat', 'filetype', current_indent }, lualine_y = { 'progress' }, lualine_z = { 'location' }, }, diff --git a/nvim/lua/plugins/vim-sleuth.lua b/nvim/lua/plugins/vim-sleuth.lua index 1bb93cb..b015bb2 100644 --- a/nvim/lua/plugins/vim-sleuth.lua +++ b/nvim/lua/plugins/vim-sleuth.lua @@ -1,5 +1,6 @@ return { { -- Detect tabstop and shiftwidth automatically + -- Run `:verbose Sleuth` to have the plugin display the reason it set options to what 'tpope/vim-sleuth', }, }