Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 5 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.

share|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
2  
This isn't enabled by default on some systems. Just add set showcmd to your vimrc to enable it. –  Tyler Holien Mar 14 '13 at 15:48
: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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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