Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Vim, how do I 'set statusline' to align right?

Tags:

vim

My ~/.vimrc uses the following statusline setting

set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ [0x\%02.2B]\ %l/%L,%v\ %p%%

Everything is left aligned. help 'statusline' says that the - character is used to "Left justify the item. The default is right justified when minwid is larger than the length of the item."

However, I haven't been able to use (or not use) - to ever align things to the right.

What is an example of having one group of items left aligned and one group right aligned?

I've also tried to use = but it just prints the = sign.

like image 678
Robert Avatar asked Dec 01 '10 07:12

Robert


People also ask

How do I change the color of a status line in Vim?

vimrc ( :w | so % ), and the terminal mode status line should have the same colors as your color scheme: Above, hi is a shorthand for highlight , which is used to define highlight group colors.

What is Statusline in Vim?

What is a statusline in Vim? The statusline in Vim is the bar along the bottom of the Vim window. By default it does not show when you open Vim until there is more than one window.


2 Answers

You need to prefix the = with a percent sign: %=.

Using your example:

set statusline=%F%m%r%h%w\ %{&ff}\ %Y\ [0x\%02.2B]\ %=l/%L,%v\ %p%%

Will right-align the "%l/%L,%v\ %p%%" group. You should also probably force a truncation using %< in a suitable place to accommodate narrow windows:

set statusline=%F%m%r%h%w%<\ %{&ff}\ %Y\ [0x\%02.2B]\ %=l/%L,%v\ %p%%
like image 87
Jeet Avatar answered Sep 20 '22 14:09

Jeet


You must use %=

What is at the left of %= will be left aligned, and what is at the right of %= will be right aligned.

For example, here is the statusline I use.

set statusline=%f%m%r%h\ [%L]\ [%{&ff}]\ %y%=[%p%%]\ [line:%05l,col:%02v]

like image 33
Xavier T. Avatar answered Sep 19 '22 14:09

Xavier T.