Chris
Chris

Reputation: 379

Vim keyboard shortcut general word count

How do I count the words in a document in vim? According to vim's definition of a word.

Seems easy to answer however I couldn't find an answer on here as they all addressed word matches, or having it in a function. I just want the word count.

Upvotes: 1

Views: 127

Answers (3)

Chris
Chris

Reputation: 379

The keyboard shortcut is g Ctrl-g.

Thanks - Assaf Lavie

For further information about the usage of this see :help g

Thanks - Munen

For those who have access to the GNU coreutils (E.G Linux) you can use the program wc see man wc for more information

:!wc -w %<tab>

The %tab expands to the current file in the buffer

Upvotes: 5

Alain M. Lafon
Alain M. Lafon

Reputation: 1720

I like using standard shell commands for such tasks. Therefore I would pipe the text to wc. Highlight the lines you want to count the words in, then:

:!wc -w

This will replace the text with the actual wordcount. Of course you can bring back your text by undoing the last action with u.

Upvotes: 1

Assaf Lavie
Assaf Lavie

Reputation: 76063

You may also find it useful to know that you could find the answer yourself using helpgrep.

e.g.

:helpgrep count words

You can then use :cnext to flip through the search result. Result #2 in this case is what you need.

Upvotes: 5

Related Questions