nvim: Show selection in lualine

Shows number of lines and characters selected in visual mode.
This commit is contained in:
Marty Oehme 2024-06-17 15:39:53 +02:00
parent 0f46dcad28
commit 87ce74de40
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A

View file

@ -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 = {},