10

I sometimes want to check the length of a piece of text, for example in this example:

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

I would like to know the length of the string Hello, world!.

What I do now, is have the column number in rulerformat with %c, I put my cursor on the first character, then go to the last, and manually substract.

This is rather awkward, though. What I want is, for example, the length of my selection in virtual mode in the ruler, but there is no option for this as far as I can see.

Can this be done? Or in some other easier way?

1 Answer 1

14

You can set the showcmd option. From Vim's help:

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}. 

It should be on by default on Vim if you have nocompatible set.

Then, simply select what you want, and Vim will display the number of characters, or lines selected on the bottom right.

1
  • Well, that was certainly simpler than I would have expected :-) Commented Feb 6, 2015 at 11:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.