Bottom-right numbers in Vim

6

2

At the bottom right hand side of the vim editor, there are 2 numbers that display the row and column number in the following format:

495,30 

But on certain lines, this format is used:

496,9-30

What does the above format with the - mean? The cursor is still on column 30 but what is that 9 ?

Andreas Grech

Posted 2009-12-13T21:52:57.453

Reputation: 3 522

Answers

7

It refers to cursor position with respect to special characters (ie: tab).

Say your screen was like this (small screen, I know):

1 x x x x x x x x x x - - - - - - - - - - - - - - - 
2 - - - - - - - - - - - - - - - - - - - - - - - - -
3 - - - - - - - - - - - - - - - - - - - - - - - - - 
4 - - - - - - - - - - - - - - - - - - - - - - - - -
5 - - x            ---           ---          --- x
6 - - - - - - - - - - - - - - - - - - - - - - - - -
7 - - - - - - - - - - - - - - - - - - - - - - - - -
8 x x x x x x x x x x x x x x x x x x x x x x x x x

Any single character (except unicode) = 1 byte
3 attached lines (---) = Tab = 1 byte
1 space (-) = 1 byte

Tab is configured to display over 8 columns.

If your cursor was on the last X in line 1, Vim would show 1,10. If it was on the first X in line 5, it would show 5,3. The last X in line 8 represents 8,25. However, since the second X on line 5 is separated by 3 Tab sequences, if your cursor was on the last X, it would show 5,7-25.

  • The first 5 is obviously the line number
  • The 7 represents the byte number in the column (2 spaces, an x, 3 tabs, and the last x = 7)
  • The 25 represents the column as you see it in the console. Using 25 spaces would be at the same position as 2 spaces, an x, 3 tabs, and another x. As you can see, the 25th X in line 8 lines up with the last X in line 5.

John T

Posted 2009-12-13T21:52:57.453

Reputation: 149 037

+1 Excellent, thanks for the detailed explanation. – Andreas Grech – 2009-12-13T22:51:09.140

5

From the Vim "options.txt" help page (emphasis mine):

If the number of characters displayed is different from the number of bytes in the text (e.g., for a TAB or a multi-byte character), both the text column (byte number) and the screen column are shown, separated with a dash.

For an empty line "0-1" is shown.

For an empty buffer the line number will also be zero: "0,0-1".

For instance, if the first character of a line were a tab, and Vim was configured to display tabs over 8 columns, your ruler would say 1-8 because a tab is still just one byte, but your cursor would be on the 8th column.

You would see similar situations while browsing files containing extended Unicode characters, since they require more than one byte to store but still use just one column on the screen.

Lawrence Velázquez

Posted 2009-12-13T21:52:57.453

Reputation: 929

3

In the examples above, the byte-number is smaller than screen-column (e.g. 9-30, 7-25). This occurs when the displayed single-byte character takes up more than one screen-column.

It is also possible to have the byte-number be larger than the screen-column. This occurs when more than one byte is displayed in one (or fewer) column(s). An example is multi-byte characters such as '\xa0' (in hex notation) which may show up on the screen in a single column.

As an example, in line 5, if the second character is two-bytes and the fourth-character is also two bytes, as you move along line 5, the column numbers change as follows:

5,1
5,2   (two-byte character, appears in a single column)
5,4-3
5,5-4 (two-byte character, appears in a single column)
5,7-5

user650654

Posted 2009-12-13T21:52:57.453

Reputation: 131