Vim – Format of Default Statusline

vim

I read about how to update the vim statusline here. And I am able to update it successfully.

But, I would like to retain the format of default vim statusline and just add some more info to it e.g. file-size, file-type, etc.

Vim default status line is:

   <file-name>                              line_num,col_num        %file

How could I do the following?

  1. I would like to add info after the file-name
  2. Display the current format of statusline (:set statusline displays nothing)

I tried:

set statusline+=%y

But this overwrites the entire statusline and just displays the file-type (%y).

Any hints?

Best Answer

Like @muru said, it doesn't seem to possible to exactly simulate the default status line when statusline is set as the code for rendering it does things that can't be specified in the statusline setting. It is possible to get pretty close, however. Here is a reasonable approximation of the way the default status line looks when ruler is enabled:

:set statusline=%f\ %h%w%m%r\ %=%(%l,%c%V\ %=\ %P%)

The main difference is the positioning of the line and column numbers. If it's possible to simulate the default spacing logic, I haven't been able to figure out a way to do it. Perhaps this will be close enough for your purposes.

I use a split version of this in my own .vimrc to place Syntastic status line info in the middle of what looks like a normal vim status line with ruler:

" start of default statusline
set statusline=%f\ %h%w%m%r\ 
" NOTE: preceding line has a trailing space character

" Syntastic statusline
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*

" end of default statusline (with ruler)
set statusline+=%=%(%l,%c%V\ %=\ %P%)
Related Question