From 1a6ab5f2f43c500e62209e545fa49c57c8132485 Mon Sep 17 00:00:00 2001 From: BlakeJC94 Date: Wed, 19 Oct 2022 20:06:45 +1100 Subject: [PATCH] feat: added searchcount component (#869) * feat: added searchcount component * feat: added timeout and maxcount to vim.fn.searchcount * docs: added searchcount to README * style: sorted list of components --- README.md | 1 + lua/lualine/components/searchcount.lua | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 lua/lualine/components/searchcount.lua diff --git a/README.md b/README.md index a7505ad..b0e18ba 100644 --- a/README.md +++ b/README.md @@ -251,6 +251,7 @@ sections = {lualine_a = {'mode'}} - `location` (location in file in line:column format) - `mode` (vim mode) - `progress` (%progress in file) +- `searchcount` (number of search matches when hlsearch is active) - `tabs` (shows currently available tabs) - `windows` (shows currently available windows) diff --git a/lua/lualine/components/searchcount.lua b/lua/lualine/components/searchcount.lua new file mode 100644 index 0000000..1b8fe2b --- /dev/null +++ b/lua/lualine/components/searchcount.lua @@ -0,0 +1,11 @@ +local function searchcount() + if vim.v.hlsearch == 0 then + return "" + end + + local result = vim.fn.searchcount({ maxcount = 999, timeout = 500 }) + local denominator = math.min(result.total, result.maxcount) + return string.format("[%d/%d]", result.current, denominator) +end + +return searchcount