vim/lualine: add custom searchcount component
This commit is contained in:
parent
6244808688
commit
ea9cd3872d
2 changed files with 38 additions and 1 deletions
|
@ -1,5 +1,7 @@
|
|||
local M = {}
|
||||
|
||||
-- filename component
|
||||
|
||||
M.filename = require('lualine.component'):extend()
|
||||
|
||||
function M.filename:init(options)
|
||||
|
@ -35,6 +37,7 @@ function M.filename:update_status(is_focused)
|
|||
end
|
||||
end
|
||||
|
||||
-- mode component
|
||||
|
||||
M.mode = require('lualine.component'):extend()
|
||||
|
||||
|
@ -67,6 +70,37 @@ function M.mode:update_status(is_focused)
|
|||
return ' '
|
||||
end
|
||||
|
||||
-- searchcount component
|
||||
|
||||
M.searchcount = require('lualine.component'):extend()
|
||||
|
||||
function M.searchcount:init(options)
|
||||
M.searchcount.super.init(self, options)
|
||||
self.options = vim.tbl_extend('keep', self.options or {}, {
|
||||
maxcount = 999,
|
||||
timeout = 250,
|
||||
})
|
||||
end
|
||||
|
||||
function M.searchcount:update_status()
|
||||
if vim.v.hlsearch == 0 then
|
||||
return ''
|
||||
end
|
||||
|
||||
local count = vim.fn.searchcount {
|
||||
maxcount = self.options.maxcount,
|
||||
timeout = self.options.timeout
|
||||
}
|
||||
if next(count) == nil then
|
||||
return ''
|
||||
end
|
||||
|
||||
local denominator = count.total > count.maxcount and '' or string.format('%d', count.total)
|
||||
return string.format(' %d/%s', count.current, denominator)
|
||||
end
|
||||
|
||||
-- trailing_whitespace component
|
||||
|
||||
M.trailing_whitespace = function()
|
||||
local pattern = [[\s\+$]]
|
||||
local lineno = vim.fn.search(pattern, 'nwc')
|
||||
|
@ -84,6 +118,8 @@ M.trailing_whitespace = function()
|
|||
return result
|
||||
end
|
||||
|
||||
-- modifier to color component when window is in focus
|
||||
|
||||
M.colored_if_focused = function(component)
|
||||
if type(component) == 'string' then
|
||||
local c = require('lualine.components.' .. component):extend()
|
||||
|
|
|
@ -48,6 +48,7 @@ return {
|
|||
},
|
||||
cond = function() return vim.o.paste end
|
||||
},
|
||||
searchcount = require('fschauen.lualine').searchcount,
|
||||
status = {
|
||||
colored_if_focused(function(_)
|
||||
local status = ''
|
||||
|
@ -71,7 +72,7 @@ return {
|
|||
lualine_a = { C.paste, C.mode },
|
||||
lualine_b = { C.branch },
|
||||
lualine_c = { C.filename, C.status },
|
||||
lualine_x = { C.diagnostics, C.filetype },
|
||||
lualine_x = { C.diagnostics, C.searchcount, C.filetype },
|
||||
lualine_y = { C.fileformat, 'progress' },
|
||||
lualine_z = { 'location', C.trailing_whitespace },
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue