From 253a656ca50db2a6f908c5ae5095dda8490e8d5d Mon Sep 17 00:00:00 2001 From: Myshko Dm <25669613+dmyTRUEk@users.noreply.github.com> Date: Thu, 30 Mar 2023 08:34:32 +0300 Subject: [PATCH] feat: add selectioncount component (#959) --- README.md | 1 + lua/lualine/components/selectioncount.lua | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 lua/lualine/components/selectioncount.lua diff --git a/README.md b/README.md index 68be212..adabb9d 100644 --- a/README.md +++ b/README.md @@ -252,6 +252,7 @@ sections = {lualine_a = {'mode'}} - `mode` (vim mode) - `progress` (%progress in file) - `searchcount` (number of search matches when hlsearch is active) +- `selectioncount` (number of selected characters or lines) - `tabs` (shows currently available tabs) - `windows` (shows currently available windows) diff --git a/lua/lualine/components/selectioncount.lua b/lua/lualine/components/selectioncount.lua new file mode 100644 index 0000000..a763936 --- /dev/null +++ b/lua/lualine/components/selectioncount.lua @@ -0,0 +1,16 @@ +local function selectioncount() + local mode = vim.fn.mode(true) + local line_start, col_start = vim.fn.line("v"), vim.fn.col("v") + local line_end, col_end = vim.fn.line("."), vim.fn.col(".") + if mode:match("") then + return string.format('%dx%d', math.abs(line_start-line_end)+1, math.abs(col_start-col_end)+1) + elseif mode:match("V") or line_start ~= line_end then + return math.abs(line_start - line_end) + 1 + elseif mode:match("v") then + return math.abs(col_start - col_end) + 1 + else + return '' + end +end + +return selectioncount