From 17676d62b9eb0acc59e501dd158de2e2ace3824c Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Tue, 27 Aug 2024 22:12:05 +0200 Subject: [PATCH] nvim: ui: install nvim-ufo and statuscol.nvim for better folds and status column. --- nvim/lua/user/plugins/ui.lua | 44 ++++++++++++++++++++++++++++++++++++ nvim/lua/user/utils/ufo.lua | 31 +++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 nvim/lua/user/utils/ufo.lua diff --git a/nvim/lua/user/plugins/ui.lua b/nvim/lua/user/plugins/ui.lua index 41ed1f4..8d10d97 100644 --- a/nvim/lua/user/plugins/ui.lua +++ b/nvim/lua/user/plugins/ui.lua @@ -19,6 +19,50 @@ return { } } }, + { + 'kevinhwang91/nvim-ufo', + dependencies = { + 'kevinhwang91/promise-async', + }, + opts = { + fold_virt_text_handler = require("user.utils.ufo").foldtext + } + }, + { + "luukvbaal/statuscol.nvim", + opts = function() + local builtin = require("statuscol.builtin") + return { + -- Align current relative number to the right. + relculright = true, + segments = { + { + click = "v:lua.ScSa", + sign = { + namespace = { "gitsigns" }, + maxwidth = 1, + colwidth = 1, + } + }, + { + click = "v:lua.ScSa", + sign = { + namespace = { "diagnostic/signs" }, + maxwidth = 1, + colwidth = 3, + -- auto = true, + } + }, + { + text = { builtin.lnumfunc, " " }, + click = "v:lua.ScLa", + }, + { text = { builtin.foldfunc, " " }, click = "v:lua.ScFa" }, + { text = { "│ " } }, + } + } + end, + }, -- File explorer { "nvim-neo-tree/neo-tree.nvim", diff --git a/nvim/lua/user/utils/ufo.lua b/nvim/lua/user/utils/ufo.lua new file mode 100644 index 0000000..688365c --- /dev/null +++ b/nvim/lua/user/utils/ufo.lua @@ -0,0 +1,31 @@ +local M={} + +M.foldtext = function(virtText, lnum, endLnum, width, truncate) + local newVirtText = {} + local suffix = (' --- %d '):format(endLnum - lnum) + local sufWidth = vim.fn.strdisplaywidth(suffix) + local targetWidth = width - sufWidth + local curWidth = 0 + for _, chunk in ipairs(virtText) do + local chunkText = chunk[1] + local chunkWidth = vim.fn.strdisplaywidth(chunkText) + if targetWidth > curWidth + chunkWidth then + table.insert(newVirtText, chunk) + else + chunkText = truncate(chunkText, targetWidth - curWidth) + local hlGroup = chunk[2] + table.insert(newVirtText, {chunkText, hlGroup}) + chunkWidth = vim.fn.strdisplaywidth(chunkText) + -- str width returned from truncate() may less than 2nd argument, need padding + if curWidth + chunkWidth < targetWidth then + suffix = suffix .. (' '):rep(targetWidth - curWidth - chunkWidth) + end + break + end + curWidth = curWidth + chunkWidth + end + table.insert(newVirtText, {suffix, 'MoreMsg'}) + return newVirtText +end + +return M