Is there an easy way to count the number of characters in a selected
area with VIM?
What I need is a way to select some text, press a key and have the
number of characters displayed somewhere in the VIM window.
Thanks in advance.
Alex
Select the text, press gCTRL-G, and all the information appears at the
bottom.
Almost what you want, but it tells you the number of bytes, not the
number of characters.
Thanks.
So you are saying that number of bytes is equal to number of
characters?
It's the same if you're using only ASCII (Roman letters basically).
But if you're typing in Chinese, say, it will take at least two bytes to
represent each character. I'm not sure exactly what vim counts in that
case-- UTF-8 bytes possibly, even if fileencoding is set to latin1 (I
seem to get four bytes for two French accented characters with gCTRL-G
even if fileencoding=latin1). It may depend on the terminal you're
running vim in.
> But if you're typing in Chinese, say, it will take at least two bytes to
> represent each character. I'm not sure exactly what vim counts in that
> case-- UTF-8 bytes possibly, even if fileencoding is set to latin1 (I
> seem to get four bytes for two French accented characters with gCTRL-G
> even if fileencoding=latin1). It may depend on the terminal you're
> running vim in.
Vim uses encoding, not fileencoding.
With enc=UFT-8, Vim counts bytes and characters.
--
Patrick Texier
vim:syntax=mail:ai:ts=4:et:tw=72
I see, that explains it, thanks.
> With enc=UFT-8, Vim counts bytes and characters.
You're right. So OP just has to make sure encoding is set to utf-8.
Humm, maybe I miss something, this does not work well for me:
1) :set encoding=UTF8
2) Type abc
3) Put the cursor on the first chararcter
3) Type gCTRL-G
Vim says: character 1 of 4
I need Vim to count exactly only the "visible" characters like
alphanumeric characters, punctuation white spaces. In a way that mimic
word count by some word processor like MS Office. Is that possible?
Maybe I'm missing something now, but didn't you ask for a character
count in the selected area? You need to select something first (between
steps 3 and 3 in your list ;-)
stefan
Uhmm.. you are right I asked for that ;-)
But that does not change the issue. If I select the first char and
tipe gCTRL-G Vim says: 1 of *4* characters.
So maybe there Vim count a hidden chars like carriage return or stuff
like that even if I did't press any other key after the last char. Is
it right?
Alex
Yes I think it's the newline. Vim always saves files with a newline at
the end.
Well, I say "always", I expect there's an option somewhere to turn that
off.