From 21f06b55a0e968c949e742b6ee10c8c9821eec47 Mon Sep 17 00:00:00 2001 From: robin Date: Sat, 13 Jun 2026 14:45:55 +0200 Subject: [PATCH] plugin: custom statuscolumn --- config/lua/ivy/config/options.lua | 2 +- config/plugin/statuscolumn.lua | 47 +++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 config/plugin/statuscolumn.lua diff --git a/config/lua/ivy/config/options.lua b/config/lua/ivy/config/options.lua index 6f9549c..b2ff3b0 100644 --- a/config/lua/ivy/config/options.lua +++ b/config/lua/ivy/config/options.lua @@ -249,7 +249,7 @@ local function setfolds() vim.o.foldenable = true vim.o.foldlevel = 99 vim.o.foldlevelstart = 99 - vim.o.foldcolumn = "1" + vim.o.foldcolumn = "0" vim.o.foldnestmax = 1 vim.o.foldmethod = "indent" end diff --git a/config/plugin/statuscolumn.lua b/config/plugin/statuscolumn.lua new file mode 100644 index 0000000..2ceb30f --- /dev/null +++ b/config/plugin/statuscolumn.lua @@ -0,0 +1,47 @@ +if vim.g.loaded_statuscolumn then + return +end + +vim.g.loaded_statuscolumn = true + +local function hl(name, str) + return string.format("%%#%s#%s%%*", name, str) +end + +function _G.statuscolumn() + local num = "%l" + + ---@type string? + local foldstr + + if vim.v.virtnum == -1 then + num = " " + elseif vim.v.virtnum > 0 then + num = "|" + end + + if vim.fn.foldclosed(vim.v.lnum) == vim.v.lnum then + num = ">" + elseif vim.fn.foldlevel(vim.v.lnum) > 0 then + foldstr = "│" + end + + -- apply highlights ========================================================== + + local cursorlinenr_enabled = vim.o.cursorline + and (vim.o.cursorlineopt == "both" or vim.o.cursorlineopt == "number") + + local linenrhl = "LineNr" + if + cursorlinenr_enabled and vim.v.lnum == vim.api.nvim_win_get_cursor(0)[1] + then + linenrhl = "CursorLineNr" + end + + num = hl(linenrhl, num) + foldstr = foldstr and hl("NonText", foldstr) or nil + + return "%s" .. (vim.wo.number and num or "") .. (foldstr or " ") +end + +vim.o.statuscolumn = "%{%v:lua.statuscolumn()%}" -- 2.51.2