Vim – How to Count Words in a File While Editing in Vim

vivim

I know I can use wc for counting characters, words and lines of files at the command line.

Is there any way I can can count the number of words while in vim?

Best Answer

You can count words and lines inside vi using vi's own counter:

Press g and then CTRL-g. Then the bottom line look for example like this:

Col 1 of 11; Line 1 of 106; Word 1 of 344; Byte 1 of 2644

Or use vi's method to call shell commands:

:w !wc -w

This calls the save (:w) command first and then wc -w and shows the output. Example:

:w !wc -w
344

Press ENTER or type command to continue

Press Enter to go back to vi.

Related Question