Vim Tips Wiki

Writing a valid statusline

Revision as of 20:56, June 2, 2009 by Fritzophrenic (Talk | contribs)

1,619pages on
this wiki
Tip 739 Printable Monobook Previous Next

created June 3, 2004 · complexity basic · author Bounga · version 6.0

I wanted to write a good looking statusline, grouping all the informations I need about a file and the environment. The needed things were the filename, the format of this file, its type, the position (line, column) of the cursor, the relative position in the file (%) and the date (day/month/year - hours:minutes).

There is one thing to always remember when you write a statusline. You have to escape all the blank characters and the " characters. To escape a character you have to use \, so if you want a whitespace you have to do "\ ".

Now here is the statusline:

set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}

This is true for any option set using the :set command. It is possible to work around this using single-quoted strings and the let command.


I think it is better

set statusline=%F%m%r%h%w\ (%{&ff}){%Y}[%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}

Try this:

set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%d/%m/%Y-%H:%M\")}%=\ col:%c%V\ ascii:%b\ pos:%o\ lin:%l\,%L\ %P

if you want above statusline appear when there is single window, try:

set laststatus=2

--- The status line is update on potentially *each* key stroke. So having a too dynamic modeline is going to make vim really slow.

To see the file modified time on status line

set statusline=%{strftime(\"%c\",getftime(expand(\"%:p\")))}

Here's the statusline I'm currently using:

set statusline=%<%F%h%m%r%h%w%y\ %{&ff}\ %{strftime(\"%c\",getftime(expand(\"%:p\")))}%=\ lin:%l\,%L\ col:%c%V\ pos:%o\ ascii:%b\ %P

Around Wikia's network

Random Wiki