10

here's a Vim question that I haven't been able to find the answer for. What does the %V statusline variable do?

I checked the documentation I could find, but it's not really clear, I am aware it shows the virtual column, but what do the numbers/letters before the - mean?

For example, what do each of the following mean?

0-1
17-18

etc. From what I can manage, while finding these examples. the number before the - is the last solid column, real column in other words. Is this correct?

Thanks for your help!

greduan
  • 4,770
  • 6
  • 45
  • 73

1 Answers1

19

In the Vim statusline, amongst the many flags you can set, there exist:

  • %c -- column number, i.e. byte number.
  • %v and %V -- virtual column number, i.e. column number on your screen.

So what is the difference between the actual and virtual column number? The answer is, that when using tabs, the virtual column number is an approximation of your current column number as if you were using spaces instead of tabs.

Example. A useful combination in the Vim statusline is:

%c%V

As it says in the help, the %V flag, which displays the virtual column number, will only be printed (with a preceding dash) when it differs from the actual column number. Thus, normally your statusline would show only the real column number (e.g., 8), but if you are on a line with tabs or multi-byte characters, you will see two numbers (e.g. 1-8).

For instance, try this:

echo -e "\tHello world." > /tmp/test

Then, open /tmp/test in Vim and notice your status line indicating the difference between the real and virtual columns. If you change the tabstop setting to a different value, the virtual column will change.

Finally, if you :set expandtab and do :retab, then the virtual column indicator will be hidden.

Hugo Ideler
  • 10,094
  • 2
  • 20
  • 22
  • +1. Although this isn't really clear, from what I can understand, and it doesn't answer my question. My question is what the numbers are before the `-`. Still, @romainl answered it for me, it was the `%c` before the `%V`. Anyway, thanks for your answer and your time, I will accept the answer as it's the only one. :) – greduan Nov 24 '12 at 20:08
  • 2
    @Eduan Difference between column and virtual column is not covered by only tabs. There are other examples: `“` character represented in UTF-8 occupies 3 columns (3 bytes: E2 80 9C), but only 1 virtual column. `A` (FULLWIDTH LATIN CAPITAL A) occupies 3 columns (UTF-8) and 2 virtual columns (fullwidth!). As you see “virtual column number is an approximation of your current column number as if you were using spaces instead of tabs” is completely false statement, virtual column number is a number of display cell where certain character ends (official: “screen column of the file position”). – ZyX Nov 24 '12 at 20:17
  • Ah I see @ZyX I suppose this is only true with variable-width fonts? Or is it also true for monospaced fonts? – greduan Nov 24 '12 at 20:22
  • Also, there is no *approximation*, it always gives exact value. And columns in vim are *byte offsets*, they have nothing to do with displayed columns. – ZyX Nov 24 '12 at 20:22
  • @Eduan Fullwidth character occupies two display cells in monospace font. – ZyX Nov 24 '12 at 20:23
  • In variable width fonts they occupy unknown space (just like any other character), thats all the difference. – ZyX Nov 24 '12 at 20:24
  • @ZyX Oh I see, well, I wasn't aware of what full width chars are, now I am. OK, that clarifies some things. Thanks! – greduan Nov 24 '12 at 20:25