From 8e5ebac114003b06fa6d221d9ed3d79e002b404f Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 5 Jul 2024 14:29:56 +0200 Subject: Hide signcolumn if there are no signs to show --- config/.config/nvim/lua/config/options.lua | 14 ++++++++++++++ config/.config/nvim/lua/plugins/_ui.lua | 3 --- config/.config/nvim/lua/utils/init.lua | 29 +++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/config/.config/nvim/lua/config/options.lua b/config/.config/nvim/lua/config/options.lua index 4080d92..4eaa25a 100644 --- a/config/.config/nvim/lua/config/options.lua +++ b/config/.config/nvim/lua/config/options.lua @@ -229,6 +229,20 @@ vim.g.loaded_python3_provider = 0 -- Turn off autoformatting in LazyVim vim.g.autoformat = false +-- Show deprecation warnings +vim.g.deprecation_warnings = true + +-- Statuscolumn +vim.opt.statuscolumn = [[%!v:lua.require'utils'.statuscolumn()]] + +-- Signcolumn +vim.opt.signcolumn = "auto" +-- utils.statuscolumn() uses vim.g.signcolumn to determine if we should show +-- signcolumn, and it will reset vim.opt.signcolumn. This is because +-- utils.statuscolumn() calls lazyvim.util.ui.statuscolumn(), which uses +-- vim.opt.signcolumn. +vim.g.signcolumn = "auto" + --------------------------------------------------------------------------------- -- -- Moving around, tabs, windows, and buffers diff --git a/config/.config/nvim/lua/plugins/_ui.lua b/config/.config/nvim/lua/plugins/_ui.lua index 2e4326d..924e4d8 100644 --- a/config/.config/nvim/lua/plugins/_ui.lua +++ b/config/.config/nvim/lua/plugins/_ui.lua @@ -24,9 +24,6 @@ return { -- "akinsho/bufferline.nvim", --}, - -- TODO: Add plugin for statuscolumn - -- I want a thinner statuscolumn when there are no gitsigns or debug-stuff shown. - { -- https://github.com/nvim-lualine/lualine.nvim "nvim-lualine/lualine.nvim", opts = { diff --git a/config/.config/nvim/lua/utils/init.lua b/config/.config/nvim/lua/utils/init.lua index 6aa0a91..2ea5316 100644 --- a/config/.config/nvim/lua/utils/init.lua +++ b/config/.config/nvim/lua/utils/init.lua @@ -15,4 +15,33 @@ M.lazy = { end, } +function M.statuscolumn() + -- lazyvim.util.ui.statuscolumn uses vim.wo[win].signcolumn to determine if it should show signcolumn + -- + + local win = vim.g.statusline_winid + local buf = vim.api.nvim_win_get_buf(win) + local next = next -- https://stackoverflow.com/a/1252776 + local signcolumn = vim.g.signcolumn + + -- If there are no signs to show, nvim_buf_get_extmarks() will return {} + -- also,