How do I customize Vim's statusline to show useful file information?
Answer
:set statusline=%f\ %y\ [%l/%L]
Explanation
Vim's statusline option lets you build a custom status bar from format items. A well-configured statusline surfaces the current filename, file type, cursor position, and more — all without a plugin.
How it works
%f\ %y\ [%l/%L] uses statusline format specifiers:
%f— Relative path of the current file\— A literal space (the backslash escapes it in the:setcommand)%y— File type in brackets, e.g.[go],[python]%l— Current line number%L— Total number of lines in the buffer
You can extend this with more items:
%m— Modified flag ([+]when unsaved changes exist)%r— Readonly flag ([RO])%c— Current column number%p%%— Percentage through the file (the%%outputs a literal%)%=— Separator that pushes everything after it to the right side
Example
A practical statusline for your vimrc:
set laststatus=2
set statusline=%f\ %m%r%y\ %=%l/%L\ col:%c
With a modified Go file open at line 42 of 200, column 10, this displays:
src/main.go [+][go] 42/200 col:10
Tips
set laststatus=2ensures the statusline is always visible (not just in split windows).- Wrap sections in
%{...}to embed Vimscript expressions:%{&fileencoding}shows encoding. - Use
%#GroupName#to apply highlight groups for color:%#WarningMsg#%m%#StatusLine#. - For complex statuslines, assign a string to
&statuslinein your vimrc rather than using:set.