feat: add selectioncount component (#959)

This commit is contained in:
Myshko Dm 2023-03-30 08:34:32 +03:00 committed by GitHub
parent 87b7145aab
commit 253a656ca5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -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)

View File

@ -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