I wonder is there a way to count highlighted symbols in vim (including white spaces)?

UPDATE

VIM visual mode

It shows rows count if my selection is on multiple rows. I need symbols count.

link|improve this question

67% accept rate
feedback

2 Answers

up vote 3 down vote accepted

Unless I'm missing something, Vim already does that. If I highlight some text using the mouse or by typing v and moving the cursor, I see at the bottom of the screen

-- VISUAL --                                        12

where the number on the right is the number of highlighted characters.

You can also visually select some region of text and type g Ctrl-G which will show the number of lines, words and bytes selected.

link|improve this answer
(stunned) How the heck did I use Vim for so long and never notice that ? But in my defense, I was thinking about obtaining the number programmatically. – njd May 27 '11 at 8:44
Good answer, but take a look at updated question. As well as @njd I did not notice that. – Nemoden May 27 '11 at 9:28
@Nemoden: Try the second part of garyjohn's suggestion (g Ctrl-G). It should show a line like "Selected # of # Lines; # of # Words; # of # Bytes." – user112553 May 27 '11 at 9:48
Oh. My bad. I don't know why I've skipped the second solution. It works. Thank you! – Nemoden May 27 '11 at 9:50
feedback
:function VisualLength()
:  exe 'normal "xy'
:  echo "Visual: " . strlen(@x) . "\n"
:  exe 'normal gv'
:endfunction

:map ,q "xy:call VisualLength()<CR>
  1. First you yank the current selection (into buffer x)

  2. Then you display the length of that buffer: strlen(@x)
    (The -- VISUAL -- displayed in the status line obscures this, so we have to add a newline)

  3. Highlight the previous visual range: gv

This doesn't take account of whether the visual mode was line-, character- or block-mode, but it's enough for most cases.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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