Zeichen zählen mit vi?

Software besorgen und anwenden
Post Reply
Message
Author
User avatar
julius
Posts: 209
Joined: 10. Apr 2001 11:08
Location: Hannover
Contact:

Zeichen zählen mit vi?

#1 Post by julius »

Kann man im vi resp. vim irgendwie die geschrieben Zeichen (inkl. Leerzeichen) vom Editor zählen lassen?

Danke,
Julius
Last edited by julius on 25. Jun 2002 19:50, edited 1 time in total.

Descartes

Re: Zeichen zählen mit vi?

#2 Post by Descartes »

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
==============================================================================

*12.4* Count words

Sometimes you have to write a text with a maximum number of words. Vim can
count the words for you.
When the whole file is what you want to count the words in, use this
command:

g CTRL-G

Do not type a space after the g, this is just used here to make the command
easy to read.
The output looks like this:

Col 1 of 0; Line 141 of 157; Word 748 of 774; Byte 4489 of 4976

You can see on which word you are (748), and the total number of words in the
file (774).

When the text is only part of a file, you could move to the start of the text,
type "g CTRL-G", move to the end of the text, type "g CTRL-G" again, and then
use your brain to compute the difference in the word position. That's a good
exercise, but there is an easier way. With Visual mode, select the text you
want to count words in. Then type g CTRL-G. The result:

Selected 5 of 293 Lines; 70 of 1884 Words; 359 of 10928 Bytes

For other ways to count words, lines and other items, see |count-items|.

==============================================================================
</font><hr></pre></blockquote>

User avatar
julius
Posts: 209
Joined: 10. Apr 2001 11:08
Location: Hannover
Contact:

Re: Zeichen zählen mit vi?

#3 Post by julius »

Danke erst mal, wo hast Du das denn her?
Aber ich brauche nicht nur Wörter, sondern alle Zeichen (inkl. Leerzeichen) - hast Du da auch etwas für mich? <img src="http://www.pl-forum.de/UltraBoard/Images/Wilk.gif" border="0" align="middle">

Julius

Descartes

Re: Zeichen zählen mit vi?

#4 Post by Descartes »

""
""Danke erst mal, wo hast Du das denn her?
""

:help usr_toc
bzw.
Hilfe -> Handbuch

und dann weiter nach in Abschnitt 12 "Clever Tricks"
:help usr_12

""
""Aber ich brauche nicht nur Wörter, sondern alle Zeichen (inkl. Leerzeichen) - hast Du da auch etwas für mich?
""

<blockquote><pre><font size="1" face="">code:</font><hr><font face="Courier New" size="2">
When the whole file is what you want to count the words in, use this
command: >

g CTRL-G

Do not type a space after the g, this is just used here to make the command
easy to read.
The output looks like this:

Col 1 of 0; Line 141 of 157; Word 748 of 774; Byte 4489 of 4976 ~
^^^^
You can see on which word you are (748), and the total number of words in the
file (774).
</font><hr></pre></blockquote>

Wenn du nicht gerade eine Unicode-Datei (2Byte pro Zeichen) bearbeitest stimmt die Dateigrösse mit der Anzahl der Zeichen überein.

Jochen

Re: Zeichen zählen mit vi?

#5 Post by Jochen »

Kleines Detail am Rande: Newlines werden natürlich auch mitgezählt. Entweder es reicht die Genauigkeit auch so, oder man sollte noch mal die Anzahl der Zeilen von der Anzahl der Bytes abziehen (im Kopf, im bc oder in der Shell <img src="http://www.pl-forum.de/UltraBoard/Images/Happy.gif" border="0" align="middle"> ).

Jochen

Post Reply