Using Vim, how do I 'set statusline' to align right?
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 de开发者_StackOverflowfault 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.
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%%
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]
Agree with Xavier T.
using %=
which means right-align following items
The fallowing is my vimrc
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}][TYPE=%Y][ASCII=\%03.3b][HEX=\%02.2B]%=[POS=%04l,%04v][%p%%][LEN=%L]
精彩评论