| Register | FAQ | Calendar | Search | Today's Posts | Mark Forums Read |
|
#1
| |||
| |||
| Hi all. 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 |
|
#2
| |||
| |||
| On 2008-09-05, Alex <metallourlante@gmail.com> wrote: > Hi all. > > 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. 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. |
|
#3
| |||
| |||
| On 5 Set, 09:31, Ben C <spams...@spam.eggs> wrote: > On 2008-09-05, Alex <metallourla...@gmail.com> wrote: > > > Hi all. > > > 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. > > 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? |
|
#4
| |||
| |||
| On 2008-09-05, Alex <metallourlante@gmail.com> wrote: > On 5 Set, 09:31, Ben C <spams...@spam.eggs> wrote: >> On 2008-09-05, Alex <metallourla...@gmail.com> wrote: >> >> > Hi all. >> >> > 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. >> >> 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. |
|
#5
| |||
| |||
| Le Fri, 05 Sep 2008 04:10:32 -0500, Ben C a écrit*: > 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 |
|
#6
| |||
| |||
| On 2008-09-05, Patrick Texier <p.texier@alussinan.org> wrote: > Le Fri, 05 Sep 2008 04:10:32 -0500, Ben C a écritÂ*: > >> 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. 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. |
|
#7
| |||
| |||
| On Sep 5, 12:42 pm, Ben C <spams...@spam.eggs> wrote: > On 2008-09-05, Patrick Texier <p.tex...@alussinan.org> wrote: > > > Le Fri, 05 Sep 2008 04:10:32 -0500, Ben C a écrit : > > >> 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. > > 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? |
|
#8
| |||
| |||
| On 2008-09-06 15:00, Alex wrote: > 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 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 |
|
#9
| |||
| |||
| On Sep 6, 6:34 pm, Stefan Weiss <spaceman-4e64c-20080...@ausgehaucht.sensenmann.at> wrote: > On 2008-09-06 15:00, Alex wrote: > > > 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 > > 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 ;-) 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 |
|
#10
| |||
| |||
| On 2008-09-07, Alex <metallourlante@gmail.com> wrote: > On Sep 6, 6:34 pm, Stefan Weiss ><spaceman-4e64c-20080...@ausgehaucht.sensenmann.at> wrote: >> On 2008-09-06 15:00, Alex wrote: >> >> > 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 >> >> 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 ;-) > > 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? 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. |
![]() |
| Thread Tools | |
| Display Modes | |
In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.