tl;dr
:set statusline=%f\ %h%w%m%r%=%-14.(%l,%c%V%)\ %P
Although my suggested solution doesn't differ much from that of the other answers, I'd like to share a more detailed explanation.
original behavior
First, let's figure out how vim
draws the status line. The functions responsible are win_redr_status()
and win_redr_ruler()
.
vim
takes the buffer name, adds a space if there are any flags to follow (like [Help]
, [Preview]
, [+]
, [RO]
). Then it adds the flags.
Normally it allocates 18 character cells for the ruler. If the buffer name part doesn't fit the rest of the available space vim
truncates it from the left and adds <
at the beginning.
If there's room for keymap, it adds it at the end (right aligned).
Now, the ruler. It consists of <row>,<col>-<virtcol>
part and relative position (right aligned).
There's also a restriction that the part with the buffer name must take at least half of the width.
solution
Now let's take the value suggested by the docs:
:set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
where
%< - where to truncate the line if too long
%f - buffer name (path to a file, or something)
%h - help flag
%m - modified flag
%r - readonly flag
%= - separater between the left (buffer name) and the right (ruler) parts
%-14.(...%) - minimum field width == 14
%l - line
%c - column
%V - virtual column
%P - percentage
So, first %<
can be omitted, since by default buffer name is truncated at the beginning. Then, it's missing the preview flag (%w
). Also, when the window is less than 18 * 2
characters wide, the right part takes more than half of the status line.
So, at least we can omit %<
and add %w
:
:set statusline=%f\ %h%w%m%r%=%-14.(%l,%c%V%)\ %P
We can go further and make sure the right part doesn't take more than half of the status line:
set statusline=%!MyStatusLine()
function! MyStatusLine()
let l:w = min([14,winwidth(0)/2-3])
return '%f %h%w%m%r%=%-' . l:w . '.(%l,%c%V%) %P'
endfunction
Then we can make it depend on the features vim
was compiled with.
if has("quickfix")
...
endif
But I'd say that that is not practical, and the previous solution would suffice for most intents and purposes. However, if the last solution doesn't work for you, tell me what's wrong, and I'll try to come up with a better one.
The problem with the solution suggested by Laurence Gonsalves is that if there are no flags, there are two spaces between the left and the right parts:
:set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)