ViM: Ruler and Default Ruler Format

In ViM, the ruler can be enabled by typing:

:set ruler

When enabled, the ruler is displayed on the right side of the status line at the bottom of the window. By default, it displays the line number, the column number, the virtual column number, and the relative position of the cursor in the file (as a percentage).

Default Ruler Format

The ruler format can be set by using the rulerformat command. Curiously, the default rulerformat is empty even though it is displaying the above details! You can find this out for yourself by typing:

:set rulerformat?

A little digging into the ViM source code reveals that the default format is not a rulerformat string at all. Instead, it is formatted manually in the win_redr_ruler function of screen.c in the code! Only Bram Moolenaar must know why he does this manually instead of using rulerformat itself. πŸ™‚

Anyway, a close equivalent of the default rulerformat can be set by using:

:set rulerformat=%-14.(%l,%c%V%)\ %P

The ruler is 18 characters in length by default. (It is not 17 as the ViM documentation in options.txt claims.) 14 characters (%-14) is the minimum width reserved for line, column and virtual column numbers (%l,%c%V%). A space separates that from the relative position display (%P) which is always 3 characters in length. When rulerformat is not set, if the total length of the ruler information exceeds 18, only the left-most 18 characters are displayed. With the above format, the rightmost 18 characters are displayed.

Note: Check out a simpler alternative for the default ruler format shared by Peter FrΓΆhlich in the comments below.

Advertisements

2 thoughts on “ViM: Ruler and Default Ruler Format

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.