Skip to content

Component snippets

shadmansaleh edited this page Aug 17, 2021 · 14 revisions

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.

Trailing whitespaces

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

Mixed indent

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
Clone this wiki locally