local modes = { ["n"] = { "NORMAL", "ColorColumn" }, ["niI"] = { "NORMAL i", "ColorColumn" }, ["niR"] = { "NORMAL r", "ColorColumn" }, ["niV"] = { "NORMAL v", "ColorColumn" }, ["no"] = { "N-PENDING", "ColorColumn" }, ["i"] = { "INSERT", "StatusInsert" }, ["ic"] = { "INSERT (completion)", "StatusInsert" }, ["ix"] = { "INSERT completion", "StatusInsert" }, ["t"] = { "TERMINAL", "StatusTerminal" }, ["nt"] = { "NTERMINAL", "StatusTerminal" }, ["v"] = { "VISUAL", "StatusVisual" }, ["V"] = { "V-LINE", "StatusVisual" }, ["Vs"] = { "V-LINE (Ctrl O)", "StatusVisual" }, [""] = { "V-BLOCK", "StatusVisual" }, ["R"] = { "REPLACE", "StatusReplace" }, ["Rv"] = { "V-REPLACE", "StatusReplace" }, ["s"] = { "SELECT", "StatusVisual" }, ["S"] = { "S-LINE", "StatusVisual" }, [""] = { "S-BLOCK", "StatusVisual" }, ["c"] = { "COMMAND", "StatusCommand" }, ["cv"] = { "COMMAND", "StatusCommand" }, ["ce"] = { "COMMAND", "StatusCommand" }, ["r"] = { "PROMPT", "StatusVisual" }, ["rm"] = { "MORE", "StatusVisual" }, ["r?"] = { "CONFIRM", "StatusVisual" }, ["!"] = { "SHELL", "StatusTerminal" }, } local function current_mode() local mode = vim.api.nvim_get_mode().mode return "%#Normal#" .. " " .. "%#" .. modes[mode][2] .. "#" .. " " .. modes[mode][1] .. " " .. "%#NormalNC#" end local function get_current_file_name() local file = vim.fn.expand("%:t") if vim.fn.empty(file) == 1 then return "" end return "%#Normal#" .. " " .. file .. " " .. "%#NormalNC#" end local function git_branch() -- Safely check if gitsigns status is available local git_status = vim.b.gitsigns_status_dict if not git_status or not git_status.head or git_status.head == "" then return "" end local branch_name = "(λ • " .. git_status.head .. ")" return "%#Normal#" .. branch_name .. "%#NormalNC#" end local function git_diff() -- Safely check if gitsigns status is available local git_status = vim.b.gitsigns_status_dict if not git_status then return "" end local added, changed, removed = "", "", "" if git_status.added and git_status.added > 0 then added = "%#DiagnosticSignInfo#" .. " +" .. git_status.added end if git_status.changed and git_status.changed > 0 then changed = "%#DiagnosticSignWarn#" .. " ~" .. git_status.changed end if git_status.removed and git_status.removed > 0 then removed = "%#DiagnosticSignError#" .. " -" .. git_status.removed end if added ~= "" or changed ~= "" or removed ~= "" then return "%#Normal#" .. added .. changed .. removed .. "%#NormalNC#" .. " " else return " " end end local mc_ns = vim.api.nvim_create_namespace("nvim.multicursor") local function multicursor_status() local ok, marks = pcall(vim.api.nvim_buf_get_extmarks, 0, mc_ns, 0, -1, {}) if not ok or #marks == 0 then return "" end return "%#Normal#" .. " " .. #marks .. "x" .. " " .. "%#NormalNC#" end local function macro_status() local rec = vim.fn.reg_recording() if rec == "" then return "" end return "%#Normal#" .. " @" .. rec .. " " .. "%#NormalNC#" end local function search_count() if vim.v.hlsearch == 0 then return "" end local ok, result = pcall(vim.fn.searchcount, { maxcount = 999, timeout = 500 }) if not ok or next(result) == nil or result.total == 0 then return "" end local denominator = math.min(result.total, result.maxcount) return "%#Normal#" .. " " .. result.current .. "/" .. denominator .. " " .. "%#NormalNC#" end local function buffer_diagnostics() local errors = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.ERROR }) local warnings = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN }) local info = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.INFO }) local hint = #vim.diagnostic.get(0, { severity = vim.diagnostic.severity.HINT }) local parts = {} if hint > 0 then table.insert(parts, "%#DiagnosticSignHint#" .. hint .. "%#Normal#") end if info > 0 then table.insert(parts, "%#DiagnosticSignInfo#" .. info .. "%#Normal#") end table.insert(parts, "%#DiagnosticSignError#" .. errors .. "%#Normal#") table.insert(parts, "%#DiagnosticSignWarn#" .. warnings .. "%#Normal#") return "%#Normal#" .. " " .. table.concat(parts, " ") .. " " .. "%#NormalNC#" end local function file_type() local type = vim.bo.filetype if type == "" then return "" end return "%#Normal#" .. " " .. type .. "%#NormalNC#" end local function cursor_position() local row = vim.fn.line(".") local column = vim.fn.col(".") return "%#Normal#" .. " " .. row .. ":" .. column .. " " .. "%#NormalNC#" end -- StatusLine Modes Status = function() return table.concat({ current_mode(), get_current_file_name(), git_branch(), git_diff(), "%=", -- right align multicursor_status(), macro_status(), search_count(), buffer_diagnostics(), file_type(), cursor_position(), }) end -- Execute statusline vim.api.nvim_create_autocmd({ "BufWinEnter" }, { pattern = "*", command = "setlocal statusline=%!v:lua.Status()", })