Vim Recipes ‣ Display ‣ Changing the Status Line
You don't like the way the status line looks or would prefer if it displayed different types of information.
For example, you work with files created on different operating systems, so you'd like the file format (e.g. unix, MS-Windows, or mac) to be displayed along the bottom of the screen.
Use the :set statusline command along with a format string. The format string is the text you want displayed interspersed with variable names corresponding to the types of information you want included.
By default Vim hides the status line. To show it: :set laststatus=2.
For example, to display the file format you could use :set statusline=%{&ff}. You can surround this with arbitrary text, for example: :set statusline=format:\ %{&ff}.
Here are some common variables the status line can display:
| Name | Description |
|---|---|
| b | Value of byte under cursor. |
| c | Column number. |
| l | Line number. |
| r | Displays [RO] if file is read only. |
| t | File name (as opposed to file path) |
| y | File content type, e.g. [ruby] or [latex]. |
| \&ff | File format, e.g. unix, mac, dos. |
Variable names are prefixed with a percentage sign (%). Spaces, bars (|), and other special characters need to be backslash escaped.
Here's a longer example:
:set statusline=%t\ %y\ format:\ %{&ff};\ [%c,%l]
Sample output: .vimrc [vim] format: unix [2,3].
You may have noted that the syntax for displaying the file format was different from the other variables. The %{} syntax evaluates the expression contained within the braces and displays the result.
For example, to display the name of the current colour scheme: %{g:colors_name} (example output: morning). Or the current language: %{v:lang} (example output: en_GB.UTF-8). Here we are simply displaying the value of Vim internal variables. (See :let for a list).
The reason %{&ff} works is because ff is the Vim option for getting/setting the file format, and the & prefix is used for referring to options. The value of any option can be displayed in this way.
You can even call a function in this way. For example, to show the last modification time of the current file:
\%{strftime(\"\%c\",getftime(expand(\"\%\%\")))}
Sample output: Fri 01 May 2009 19:26:07 BST