如何轻松获得一段文本的长度?


9

有时我想检查一段文本的长度,例如在此示例中:

str = 'Hello, world!'
if len(str) == 13:
    print('Hello back to you!')

我想知道字符串的长度Hello, world!

我现在做的,就是在列号rulerformat%c,我把我的光标上的第一个字符,然后去到最后,和手动。减去。

但是,这很尴尬。例如,我想要的是在标尺中以虚拟模式进行选择的时间长度,但是据我所知,对此没有任何选择。

能做到吗?还是以其他更简单的方式?

Answers:


12

您可以设置showcmd选项。在Vim的帮助下:

Show (partial) command in the last line of the screen.  Set this
option off if your terminal is slow.
In Visual mode the size of the selected area is shown:
- When selecting characters within a line, the number of characters.
  If the number of bytes is different it is also displayed: "2-6"
  means two characters and six bytes.
- When selecting more than one line, the number of lines.
- When selecting a block, the size in screen characters:
  {lines}x{columns}.

如果已nocompatible设置,则默认情况下应在Vim上将其打开。

然后,只需选择所需的内容,Vim将显示字符数或在右下角选择的行。


好吧,那肯定比我预期的要简单:-)
Martin Tournoij
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.