vimtricks.wiki Concise Vim tricks, one at a time.

How do I set a different statusline for a specific buffer or window?

Answer

:setlocal statusline=%f\ %m\ %y\ [%l/%L]

Explanation

The :setlocal statusline command lets you override the global statusline for a specific window. This is useful when you want different information displayed for different file types — for example, a minimal statusline for help buffers or a detailed one for source code files. The local statusline takes precedence over the global statusline option for that window only.

How it works

  • :setlocal — sets the option locally for the current window (not globally)
  • statusline= — the statusline format string
  • %f — file name relative to current directory
  • %m — modified flag ([+] if modified)
  • %y — file type in brackets (e.g., [vim])
  • %l/%L — current line number / total lines

Example

Set a minimal statusline for the current window:

:setlocal statusline=%f\ %m\ %y\ [%l/%L]

Your statusline will show:

script.py [+] [python] [42/300]

Automate it per filetype in your vimrc:

autocmd FileType help setlocal statusline=%f\ [Help]
autocmd FileType qf setlocal statusline=Quickfix\ [%l/%L]

Tips

  • Use %= in the format string to separate left-aligned and right-aligned sections
  • To reset a window back to the global statusline, use :setlocal statusline= (empty value)
  • Common statusline items: %F (full path), %c (column), %p%% (percentage through file), %{&encoding} (encoding)

Next

How do I use PCRE-style regex in Vim without escaping every special character?