Are there any more examples of custom components? #486
-
I'm trying to author a whitespace/mix-indent component similar to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Check out https://github.com/nvim-lualine/lualine.nvim/wiki/Component-snippets#mixed-indent If you want to create a new type of component . You need to extened the base component class then implement Checkout components in https://github.com/nvim-lualine/lualine.nvim/tree/master/lua/lualine/components . & Base component is found here . But if you're just putting it in your config . You can just use the mixed-indent function as a component as shown here You can just do local function mixed_indent()
local space_pat = [[\v^ +]]
local tab_pat = [[\v^\t+]]
local space_indent = vim.fn.search(space_pat, 'nwc')
local tab_indent = vim.fn.search(tab_pat, 'nwc')
local mixed = (space_indent > 0 and tab_indent > 0)
local mixed_same_line
if not mixed then
mixed_same_line = vim.fn.search([[\v^(\t+ | +\t)]], 'nwc')
mixed = mixed_same_line > 0
end
if not mixed then return '' end
if mixed_same_line ~= nil and mixed_same_line > 0 then
return 'MI:'..mixed_same_line
end
local space_indent_cnt = vim.fn.searchcount({pattern=space_pat, max_count=1e3}).total
local tab_indent_cnt = vim.fn.searchcount({pattern=tab_pat, max_count=1e3}).total
if space_indent_cnt > tab_indent_cnt then
return 'MI:'..tab_indent
else
return 'MI:'..space_indent
end
end
require('lualine').setup {
lualine_x = {mixed_indent},
} |
Beta Was this translation helpful? Give feedback.
Check out https://github.com/nvim-lualine/lualine.nvim/wiki/Component-snippets#mixed-indent
If you want to create a new type of component . You need to extened the base component class then implement
update_status
method.Checkout components in https://github.com/nvim-lualine/lualine.nvim/tree/master/lua/lualine/components . & Base component is found here .
But if you're just putting it in your config . You can just use the mixed-indent function as a component as shown here
You can just do