简体   繁体   English

Vim:状态线'%V'如何工作?

[英]Vim: How does the statusline '%V' work?

here's a Vim question that I haven't been able to find the answer for. 这是一个我无法找到答案的Vim问题。 What does the %V statusline variable do? %V statusline变量有什么作用?

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! 谢谢你的帮助!

In the Vim statusline , amongst the many flags you can set, there exist: 在Vim statusline ,在您可以设置的许多标志中,存在:

  • %c -- column number, ie byte number. %c - 列号,即字节数。
  • %v and %V -- virtual column number, ie column number on your screen. %v%V - 虚拟列号,即屏幕上的列号。

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: Vim状态行中有用的组合是:

%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. 正如帮助中所述,显示虚拟列号的%V标志只有在与实际列号不同时才会打印(带有前面的短划线)。 Thus, normally your statusline would show only the real column number (eg, 8 ), but if you are on a line with tabs or multi-byte characters, you will see two numbers (eg 1-8 ). 因此,通常您的状态行仅显示实际列号(例如, 8 ),但如果您在带有制表符或多字节字符的行上,您将看到两个数字(例如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. 然后,在Vim中打开/tmp/test并注意您的状态行,指示实列和虚拟列之间的差异。 If you change the tabstop setting to a different value, the virtual column will change. 如果将tabstop设置更改为其他值,则虚拟列将更改。

Finally, if you :set expandtab and do :retab , then the virtual column indicator will be hidden. 最后,如果您:set expandtab并执行:retab ,则隐藏虚拟列指示符。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM