Neovim Statusline
README.md

statusline.nvim #

A small statusline for Neovim 0.12 or newer. It displays the current mode, tab working directory, and workspace diagnostic counts on the left, with macro-recording state, attached LSP clients, the target buffer's exact filetype, and cursor position on the right.

statusline.nvim in Normal mode with workspace diagnostics, LSP clients, filetype, and cursor position

While recording a macro, an additional box shows the exact recording register as RECORDING @<register>:

statusline.nvim while recording a macro in register q

The screenshots use the custom highlight palette shown in Customization.

Zero-count diagnostic severities and the complete diagnostics component when the workspace has no diagnostics are omitted. The macro box is omitted entirely when recording is inactive. When no LSP clients remain after filtering, the LSP box is omitted. Mode labels and filetype icons can be overridden in setup(); unconfigured mode labels retain their defaults, while unconfigured icons come from nvim-web-devicons. When neither configuration nor devicons supplies an icon, the filetype text is still shown:

Statusline showing the textonly filetype without an icon

The macro-recording screenshot above shows the complete statusline with two errors and five warnings while recording register q in a Lua buffer with lua_ls and null-ls attached in Normal mode.

Every box has one space of internal left/right padding. Present left-side boxes are assembled in mode, CWD, error, warning, info, hint order and joined by exactly one unhighlighted separator space. Zero-count severity boxes are absent. When right-side components exist, %= appears immediately after the final CWD or diagnostic box and performs right alignment once. Present right-side boxes are assembled in macro, LSP, filetype, cursor order and joined by exactly one unhighlighted space after each preceding highlight reset. The cursor-position box always uses StatusCursorPos, independently of the current mode.

The CWD box is always present, including for terminal and empty-filetype buffers. It uses vim.fn.getcwd(-1, 0), which honors the current tab's :tcd, ignores window-local :lcd, and falls back to the global working directory when the tab has no local directory. vim.fn.fnamemodify(directory, ":~") contracts the home prefix before display.

Diagnostics use that same tab-effective CWD as their workspace, so their scope cannot disagree with the displayed directory and intentionally ignores :lcd. The rendered diagnostics component has a single-entry cache keyed by the exact tab-effective CWD. The first render for a directory after invalidation inspects all valid Neovim buffers; subsequent renders reuse the formatted result, including an empty result, without listing buffers or querying diagnostics. Changing to a different tab-effective CWD performs one fresh scan and replaces the prior entry, bounding retained cache state.

During a scan, unnamed buffers are ignored; each named buffer path and the workspace CWD are normalized, and a buffer is included only when its path equals the workspace CWD or is below CWD/. This separator-aware check includes nested files while excluding sibling-prefix paths such as /work/app-copy for a /work/app workspace. Normalized paths are cached while a buffer retains the same exact name. BufFilePost, BufDelete, and BufWipeout discard the affected path entry and invalidate the rendered aggregate; each successful setup() also clears the rendered aggregate.

All diagnostics in included buffers are counted through Neovim's count API across every source and namespace, avoiding copies of complete diagnostic entries. Duplicate entries are counted independently. Nonzero severities render in the fixed order error, warning, info, hint with the fixed glyphs 󰅚 <count>, 󰀪 <count>, 󰋽 <count>, and 󰌶 <count>. If all four counts are zero, no diagnostic box or extra separator is emitted, preserving the previous statusline output exactly. DiagnosticChanged invalidates the aggregate synchronously. Diagnostic and buffer-lifecycle events coalesce :redrawstatus through one callback on the next event-loop turn, so updates stay prompt without issuing redundant redraws during event bursts. There is no diagnostics setup() option.

The macro box is omitted when no macro is being recorded, the LSP box is omitted when no clients are attached or every attached client is excluded, and the filetype box is omitted when filetype is empty. Terminal buffers still omit only the cursor box; the CWD, workspace diagnostics, and any visible macro, LSP, and filetype boxes remain:

Terminal statusline variants showing optional macro, LSP, filetype, and diagnostic boxes

Macro recording is queried on every render with vim.fn.reg_recording(). It is editor-wide state, so the box remains visible in inactive-window and terminal statuslines rather than being tied to vim.g.statusline_winid or a target buffer. RecordingEnter and RecordingLeave schedule :redrawstatus; scheduling ensures RecordingLeave has fully completed before reg_recording() is queried, avoiding its documented during-event register value.

LSP clients are queried on every render with vim.lsp.get_clients({ bufnr = buffer }), so attach and detach changes appear without extra autocmd state. Names configured in lsp_exclude are removed after the query. Remaining client names are shown exactly in Neovim's returned order, including duplicates, and separated by exactly │.

The LSP query and buffer-local filetype and buftype values use the buffer from the window identified by vim.g.statusline_winid, with the current buffer as a fallback. This keeps inactive windows' LSP and buffer information tied to their own buffers. CWD and diagnostics instead remain workspace-wide, so active, inactive, and terminal statuslines consistently show the current tab's same effective working directory and aggregate counts.

Requirements #

nvim-web-devicons remains a required runtime dependency and supplies icons for filetypes without a configured override. For an unmapped filetype, the statusline calls get_icon_by_filetype(filetype) without requesting a default icon. A missing devicons mapping falls back to the filetype text, but a missing plugin is an error. A configured mapping takes precedence and skips the devicons lookup. Literal % characters in custom mode text, working-directory paths, recording-register values, client names, custom or devicons icons, and filetype text are escaped before insertion into the statusline format.

Neovim versions older than 0.12 are rejected by setup() with an error.

Installation #

Install this repository and nvim-web-devicons with your preferred Neovim package manager, then call setup() explicitly. For example, with lazy.nvim:

{
  "vapourismo/statusline.nvim",
  dependencies = {
    "nvim-tree/nvim-web-devicons",
  },
  config = function()
    require("statusline").setup({
      mode_text = {
        normal = "N",
        insert = "I",
        visual = "V",
      },
      filetype_icons = {
        lua = "CUSTOM",
        markdown = "",
        text = "",
      },
      lsp_exclude = {
        "copilot",
        "null-ls",
      },
    })
  end,
}

For a native package installation, clone both repositories into start package directories:

git clone https://github.com/nvim-tree/nvim-web-devicons.git \
  "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/pack/plugins/start/nvim-web-devicons"

git clone REPOSITORY_URL \
  "${XDG_DATA_HOME:-$HOME/.local/share}/nvim/site/pack/plugins/start/statusline.nvim"

Then add this to init.lua:

require("statusline").setup({
  mode_text = {
    normal = "N",
    insert = "I",
    visual = "V",
  },
  filetype_icons = {
    lua = "CUSTOM",
    markdown = "",
    text = "", -- intentionally suppress the icon
  },
  lsp_exclude = {
    "copilot",
    "null-ls",
  },
})

Configuration #

Mode text #

mode_text is an optional table mapping semantic mode keys to static display strings:

require("statusline").setup({
  mode_text = {
    normal = "N",
    insert = "I",
    visual = "V",
  },
})

The supported keys, their default labels, full Neovim mode-code aliases, and unchanged highlight groups are listed in Modes and highlights. One override applies to every full mode code in that semantic family: for example, normal controls n, niI, niR, and niV. A partial map changes only its configured semantic modes; omitted keys fall back to their default labels.

Values are strings rather than per-render callbacks. Empty strings are valid and render an empty mode box with its normal left/right padding. Literal % characters are escaped for statusline syntax. Custom text changes neither mode-code resolution nor highlight selection, padding, component presence, or layout.

Filetype icons #

filetype_icons is an optional table mapping exact Neovim filetype names to icon strings. Matching is case-sensitive. A configured entry takes precedence over nvim-web-devicons and avoids its lookup for that render. An empty string deliberately suppresses the icon while retaining the filetype text.

Filetypes absent from the table continue to use nvim-web-devicons; if devicons has no mapping, only the filetype text is displayed. There is no wildcard or custom default icon, and values must be plain strings. Icon-specific highlights are not used: StatusFiletype styles the entire box.

LSP exclusions #

lsp_exclude is an optional list of exact LSP client names that should not appear in the LSP box:

require("statusline").setup({
  lsp_exclude = {
    "copilot",
    "null-ls",
  },
})

Names are matched against client.name exactly and case-sensitively; entries are not Lua patterns. Filtering does not change the per-render LSP query. Non-excluded clients retain Neovim's returned order and duplicates. If every attached client is excluded, the complete LSP box is omitted without leaving an extra separator. Duplicate and empty-string exclusion entries are accepted but normally unnecessary.

Replacement and validation #

Each successful setup() call copies and replaces the complete mode-text map, custom icon map, and exclusion list rather than merging them. Omitting any option restores that option's empty default. Calling setup() without options therefore restores all default mode labels and clears all filetype icon overrides and LSP exclusions:

require("statusline").setup({
  mode_text = {
    normal = "N",
  },
  filetype_icons = {
    lua = "LUA",
  },
  lsp_exclude = {
    "copilot",
  },
})

-- Later: restore default labels and remove all custom icons and exclusions.
require("statusline").setup()

When supplied, the setup options, mode_text, and filetype_icons must be tables. Every mode_text key must be one of the supported semantic keys and every key and value must be a string; unknown keys are rejected. Every icon-map key and value must also be a string. lsp_exclude must be a list/array containing only strings; keyed, mixed, and sparse tables are rejected. Invalid configuration raises a setup error without installing any option, so the last valid mode text, icon map, and LSP exclusions all remain active.

setup() sets the global statusline expression only. It does not change laststatus, statusline visibility, existing window-local statusline overrides, or unrelated options. Styling remains configured through highlight groups instead of component options.

Modes and highlights #

StatusCwd, StatusMacro, StatusLsp, StatusCursorPos, StatusFiletype, and every mode highlight group are created as default links to StatusLine. The four diagnostic groups instead default-link to Neovim's matching diagnostic highlights:

Severity Fixed display Highlight group Default link
Error 󰅚 <count> StatusDiagnosticError DiagnosticError
Warning 󰀪 <count> StatusDiagnosticWarn DiagnosticWarn
Info 󰋽 <count> StatusDiagnosticInfo DiagnosticInfo
Hint 󰌶 <count> StatusDiagnosticHint DiagnosticHint

Existing user definitions are not overwritten. Missing default links, including all four diagnostic links, are recreated after ColorScheme events.

StatusCwd styles the working-directory box. Each StatusDiagnostic* group styles its complete severity box. StatusMacro styles the macro-recording box. StatusLsp styles the attached-clients box. StatusCursorPos styles the cursor-position box in every mode. StatusFiletype styles the entire filetype box, including its icon. The icon-specific highlight returned by nvim-web-devicons is intentionally ignored so the box has one consistent style.

Semantic key Default display Neovim full mode codes Highlight group
normal NORMAL n, niI, niR, niV StatusModeNormal
operator_pending OPERATOR no, nov, noV, no<C-V> StatusModeOperatorPending
insert INSERT i, ic, ix StatusModeInsert
visual VISUAL v, vs StatusModeVisual
visual_line V-LINE V, Vs StatusModeVisualLine
visual_block V-BLOCK <C-V>, <C-V>s StatusModeVisualBlock
select SELECT s StatusModeSelect
select_line S-LINE S StatusModeSelectLine
select_block S-BLOCK <C-S> StatusModeSelectBlock
replace REPLACE R, Rc, Rx StatusModeReplace
virtual_replace V-REPLACE Rv, Rvc, Rvx StatusModeVirtualReplace
command COMMAND c, cr StatusModeCommand
ex EX cv, cvr StatusModeEx
prompt PROMPT r StatusModePrompt
more MORE rm StatusModeMore
confirm CONFIRM r? StatusModeConfirm
shell SHELL ! StatusModeShell
terminal TERMINAL t StatusModeTerminal
terminal_normal T-NORMAL nt, ntT StatusModeTerminalNormal
unknown UNKNOWN Any unrecognized future mode StatusModeUnknown

Completion, temporary Normal, Visual/Select variants, command-line overstrike, and terminal-Normal modes are all resolved from Neovim's full mode code.

Customization #

Define StatusCwd, any StatusDiagnostic* group, StatusMacro, StatusLsp, StatusCursorPos, StatusFiletype, or any mode group with vim.api.nvim_set_hl(). Definitions made before setup() are preserved. Diagnostics and macro display are automatic and have no setup options. For example:

vim.api.nvim_set_hl(0, "StatusCwd", {
  fg = "#1e1e2e",
  bg = "#cba6f7",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusDiagnosticError", {
  fg = "#1e1e2e",
  bg = "#f38ba8",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusDiagnosticWarn", {
  fg = "#1e1e2e",
  bg = "#f9e2af",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusDiagnosticInfo", {
  fg = "#1e1e2e",
  bg = "#89b4fa",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusDiagnosticHint", {
  fg = "#1e1e2e",
  bg = "#a6e3a1",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusMacro", {
  fg = "#1e1e2e",
  bg = "#eba0ac",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusLsp", {
  fg = "#1e1e2e",
  bg = "#94e2d5",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusCursorPos", {
  fg = "#1e1e2e",
  bg = "#fab387",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusFiletype", {
  fg = "#1e1e2e",
  bg = "#f9e2af",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusModeNormal", {
  fg = "#1e1e2e",
  bg = "#a6e3a1",
  bold = true,
})

vim.api.nvim_set_hl(0, "StatusModeInsert", {
  fg = "#1e1e2e",
  bg = "#89b4fa",
  bold = true,
})

require("statusline").setup()

To keep custom colors when switching colorschemes, reapply them on ColorScheme:

local function set_statusline_highlights()
  vim.api.nvim_set_hl(0, "StatusCwd", {
    fg = "#1e1e2e",
    bg = "#cba6f7",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusDiagnosticError", {
    fg = "#1e1e2e",
    bg = "#f38ba8",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusDiagnosticWarn", {
    fg = "#1e1e2e",
    bg = "#f9e2af",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusDiagnosticInfo", {
    fg = "#1e1e2e",
    bg = "#89b4fa",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusDiagnosticHint", {
    fg = "#1e1e2e",
    bg = "#a6e3a1",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusMacro", {
    fg = "#1e1e2e",
    bg = "#eba0ac",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusLsp", {
    fg = "#1e1e2e",
    bg = "#94e2d5",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusCursorPos", {
    fg = "#1e1e2e",
    bg = "#fab387",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusFiletype", {
    fg = "#1e1e2e",
    bg = "#f9e2af",
    bold = true,
  })

  vim.api.nvim_set_hl(0, "StatusModeVisual", {
    fg = "#1e1e2e",
    bg = "#cba6f7",
    bold = true,
  })
end

set_statusline_highlights()
vim.api.nvim_create_autocmd("ColorScheme", {
  callback = set_statusline_highlights,
})

The StatusCursorPos component uses Neovim's %l:%c fields: both values are one-based, and %c is a byte-column rather than a screen or virtual column.

Benchmarks #

Run the complete self-contained benchmark suite with Neovim 0.12+:

make benchmark

The suite has two parts:

  • Runtime benchmarks measure components, raw workspace diagnostic counts plus warm-cache and forced-invalidation diagnostic renders at 1/10/100-buffer scales, a forced cold-path count, idle and populated complete renders, a simulated multi-window redraw, Neovim statusline-expression evaluation, repeated setup, and package-uncached plugin module loading (with the operating-system filesystem cache left intact). The end-to-end evaluated cases are compared with a minimal Lua statusline callback; a built-in %l:%c evaluation is also reported.
  • Startup benchmarks launch fresh Neovim child processes and compare an init containing only the shared harness with the same init plus require("statusline").setup(). Baseline/plugin runs are paired and alternate order. Measurements come from Neovim's --startuptime NVIM STARTED marker.

A deterministic in-memory nvim-web-devicons stub avoids plugin-manager and dependency noise. Populated LSP scenarios use fixed mocked clients; diagnostics use real Neovim buffers, namespaces, and APIs. Runtime percentiles are calculated from per-batch ns/op averages. The reported memory value is Lua heap growth per operation while garbage collection is paused; it does not include all native Neovim allocations or represent retained memory.

For a fast smoke run:

make benchmark-quick

The runtime and startup portions can be run independently:

make benchmark-runtime
make benchmark-startup

The following environment variables tune runs:

Variable Purpose Default
STATUSLINE_BENCH_QUICK Use small smoke-test settings when set to 1 unset
STATUSLINE_BENCH_SAMPLES Runtime timing batches per case 15
STATUSLINE_BENCH_ITERATIONS Operations in each runtime batch 500
STATUSLINE_BENCH_WARMUP Runtime warmup operations per case 100
STATUSLINE_BENCH_MEMORY_ITERATIONS Operations used for paused-GC heap measurement 200
STATUSLINE_BENCH_SCALES Comma-separated diagnostic buffer counts 1,10,100
STATUSLINE_BENCH_FULL_BUFFERS Workspace buffers in the populated render 25
STATUSLINE_BENCH_WINDOWS Visible windows in the simulated populated redraw 4
STATUSLINE_BENCH_FILTER Run names containing this exact substring unset
STATUSLINE_BENCH_STARTUP_SAMPLES Paired fresh-process startup observations 15
STATUSLINE_BENCH_STARTUP_WARMUP Fresh-process warmup pairs 3
STATUSLINE_BENCH_FORMAT Report format: human or json human
STATUSLINE_BENCH_RUNTIME_OUTPUT Optional runtime report file unset
STATUSLINE_BENCH_STARTUP_OUTPUT Optional startup report file unset

For example, save machine-readable reports suitable for comparing revisions:

STATUSLINE_BENCH_FORMAT=json \
STATUSLINE_BENCH_RUNTIME_OUTPUT=benchmark-results/runtime.json \
STATUSLINE_BENCH_STARTUP_OUTPUT=benchmark-results/startup.json \
make benchmark

Benchmark results are sensitive to CPU scaling, background activity, Neovim builds, and LuaJIT warmup. Compare revisions on the same idle machine with identical settings and repeat the suite before drawing conclusions. The static direct-call baseline is primarily a loop floor; the evaluated Lua-callback baseline is the more relevant comparison for complete evaluated statuslines.

Tests #

Run the self-contained headless test suite with Neovim 0.12+:

make test

The suite stubs nvim-web-devicons and covers CWD shortening and tab/window-local behavior; workspace diagnostic aggregation, rendered-result and normalized-path caching, event invalidation, rename membership updates, descendant filtering, severity rendering and omission, terminal/inactive consistency, coalesced redraw hooks, and diagnostic highlights; macro recording; semantic mode-text overrides and aliases; icon overrides and precedence; LSP exclusions; deliberate icon suppression; devicons fallback calls; escaping; atomic configuration replacement, reset, and validation; complete statuslines; and idempotent setup.