-
-
Notifications
You must be signed in to change notification settings - Fork 523
Component snippets
Here we list various snippets for components that can be useful for users. Most of these are functions that can be used as regular function component in any section of lualine. If you have some nice component snippets that you want to share. You can add proposal to get them added here.
Shows 'TW' in lualine when there are trailing white space in current buffer.
function()
return vim.fn.search([[\s\+$]], 'nw') ~= 0 and 'TW' or ''
end
Shows 'MI' in lualine when both tab and spaces are used for indenting current buffer.
function()
local space_indent = vim.fn.search([[\v^ +]], 'nw') > 0
local tab_indent = vim.fn.search([[\v^\t+]], 'nw') > 0
local mixed = (space_indent and tab_indent)
or vim.fn.search([[\v^(\t+ | +\t)]], 'nw') > 0
return mixed and 'MI' or ''
end
Shows short name of currently active keymap.
See :h keymap
local function keymap()
if vim.opt.iminsert:get() > 0 and vim.b.keymap_name then
return '⌨ ' .. vim.b.keymap_name
end
return ''
end
This is quite useful to quickly switch between multiple windows.
local function window()
return vim.api.nvim_win_get_number(0)
end
require'lualine'.setup {
sections = {
lualine_a = { window },
}
}
If you have other plugins installed that keep track of branch info . lualine can reuse that info.
- vim-fugitive
lualine_b = { {'FugitiveHead', icon = ''}, },
- gitsigns.nvim
lualine_b = { {'b:gitsigns_head', icon = ''}, },
If you have other plugins installed that keep track of info. lualine can reuse that info. And you don't need to have two separate plugins doing the same thing.
- gitsigns.nvim
local function diff_source()
local gitsigns = vim.b.gitsigns_status_dict
if gitsigns then
return {
added = gitsigns.added,
modified = gitsigns.changed,
removed = gitsigns.removed
}
end
end
require'lualine'.setup {
sections = {
lualine_b = { {'diff', source = diff_source}, },
}
}
Display the fileformat section as CRLF instead of icons or unix/dos/mac
require'lualine'.setup {
sections = {
lualine_x = {
{
'fileformat',
icons_enabled = true,
symbols = {
unix = 'LF',
dos = 'CRLF',
mac = 'CR',
},
},
},
},
}