Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim: How does the statusline '%V' work?

Tags:

vim

statusline

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!

like image 900
greduan Avatar asked Nov 24 '12 19:11

greduan


1 Answers

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.

like image 114
Hugo Ideler Avatar answered Nov 11 '22 16:11

Hugo Ideler