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


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:

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.