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?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
You can count words and lines inside
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
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
You can also try for
:!wc % in Vim, though it counts the size of the file on-disk, not what is in Vim's buffer. This may or may not be what you wanted.
Plugins such as vim-airline can provide word counts for a file (and selections) as part of a status bar.
For those who want to count number of words in a given piece of text (not whole file), use
Result. Vim will show you something like this:
10 matches on 1 line
When you hit
: in visual mode, vim prepends your command with
'<,'> which means to apply the command against the selected text.
\S\+ captures words, that is groups of characters separated by whitespace.
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?