How do I customise Vim's status line to show useful file information?
Answer
:set statusline=%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
Explanation
Vim's built-in statusline option lets you build a custom status bar that displays exactly the information you want — without any plugin. Setting a useful statusline gives you constant visibility of the filename, modification state, cursor position, and scroll percentage.
How it works
The statusline option is a format string composed of % items. Here is a breakdown of the example:
set statusline=%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
| Item | Meaning |
|---|---|
%f |
Relative path to the current file |
%h |
[Help] flag if this is a help buffer |
%m |
[+] if the buffer has unsaved changes |
%r |
[RO] if the buffer is read-only |
%= |
Right-align everything that follows |
%-14.(...) |
Fixed-width group, left-aligned in 14 columns |
%l,%c%V |
Line number, column number, virtual column |
%P |
Percentage through the file |
Add :set laststatus=2 to always show the status line (not just in split windows).
Example
Add to your ~/.vimrc:
set laststatus=2
set statusline=%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
The status line will look similar to:
src/main.go [+] 42,15 45%
Tips
- Use
%Finstead of%fto show the full absolute path. - Add
%yto display the filetype (e.g.,[python]). - Use
%{&fileencoding}to display the file encoding. - Run
:help statuslinefor the complete list of available items.