From 87ce74de403d6537dacbcca038aba2f7ccd326e5 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Mon, 17 Jun 2024 15:39:53 +0200 Subject: [PATCH] nvim: Show selection in lualine Shows number of lines and characters selected in visual mode. --- nvim/.config/nvim/lua/plugins/ui.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/nvim/.config/nvim/lua/plugins/ui.lua b/nvim/.config/nvim/lua/plugins/ui.lua index 73c1a4c..9e829c3 100644 --- a/nvim/.config/nvim/lua/plugins/ui.lua +++ b/nvim/.config/nvim/lua/plugins/ui.lua @@ -29,6 +29,19 @@ return { end return "" end + + -- count number of selected lines and characters + -- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4 + local function selectionCount() + local isVisualMode = vim.fn.mode():find("[Vv]") + if not isVisualMode then + return "" + end + local starts = vim.fn.line("v") + local ends = vim.fn.line(".") + local lines = starts <= ends and ends - starts + 1 or starts - ends + 1 + return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C" + end require("lualine").setup({ options = { icons_enabled = true, @@ -44,7 +57,7 @@ return { lualine_c = { "filename" }, lualine_x = { "encoding", "fileformat", "filetype", molten }, lualine_y = { "progress" }, - lualine_z = { "location" }, + lualine_z = { selectionCount, "location" }, }, inactive_sections = { lualine_a = {},