How do I build a custom statusline without plugins?
Answer
:set statusline=%f\ %m%r%h%w\ %=%l/%L\ %p%%
Explanation
Vim's statusline option accepts printf-style format codes that display file info, position, mode, and any custom expression. You can build a functional statusline without any plugins.
Basic setup
:set laststatus=2 " Always show statusline
:set statusline=%f\ %m%r%h%w\ %=%l/%L\ Col:%c\ %p%%
This shows: src/main.go [+][RO] 42/150 Col:15 28%
Format codes
| Code | Shows |
|---|---|
%f |
Relative file path |
%F |
Full file path |
%t |
Filename only |
%m |
Modified flag [+] |
%r |
Readonly flag [RO] |
%h |
Help buffer flag |
%w |
Preview window flag |
%y |
Filetype [go] |
%l |
Current line number |
%L |
Total lines |
%c |
Column number |
%p |
Percentage through file |
%% |
Literal % |
%= |
Right-align separator |
Adding color
:set statusline=%#PmenuSel#\ %f\ %#Normal#\ %m%=%l/%L
%#HighlightGroup# switches colors using named highlight groups.
Using expressions
" Show git branch (requires fugitive or custom function)
:set statusline+=%{FugitiveStatusline()}
" Show current mode
:set statusline+=%{mode()}
" Show file encoding
:set statusline+=%{&fileencoding?&fileencoding:&encoding}
A complete statusline
set statusline=
set statusline+=\ %f " Filename
set statusline+=\ %m%r " Modified/readonly
set statusline+=\ %y " Filetype
set statusline+=%= " Right align
set statusline+=\ %{&fenc} " Encoding
set statusline+=\ %l:%c " Line:Column
set statusline+=\ %p%% " Percentage
Tips
- Build the statusline incrementally with
+= %{}evaluates any Vimscript expression- Use
%*to reset highlighting to the default - Set different statuslines for active/inactive windows using
autocmd - For more advanced needs, consider
lualine.nvim(Neovim) orvim-airline - Documented under
:help statusline