vimtricks.wiki Concise Vim tricks, one at a time.

How do I get a detailed word, character, and byte count in Vim?

Answer

g<C-g>

Explanation

While <C-g> shows basic file info (filename, line count, position), g<C-g> provides a much more detailed statistical breakdown of your file or visual selection. This is invaluable when you need precise word counts for writing tasks, or byte counts for debugging encoding issues.

How it works

  • In normal mode: g<C-g> displays the total number of columns, lines, words, characters, and bytes for the entire file, along with your current position within each
  • In visual mode: select text first, then press g<C-g> to get statistics for just the selected region

Example

With the cursor on line 5 of a 20-line file, pressing g<C-g> shows:

Col 1 of 42; Line 5 of 20; Word 38 of 150; Char 200 of 1024; Byte 200 of 1024

To count words in a specific paragraph, visually select it with vip and then press g<C-g>:

Selected 3 of 20 Lines; 25 of 150 Words; 130 of 1024 Chars; 130 of 1024 Bytes

Tips

  • Combine with visual selections to count words in specific sections — useful for meeting word limits in essays or documentation
  • The byte count differs from the character count for multibyte encodings (UTF-8), which helps diagnose encoding issues
  • For a quick line/position check, plain <C-g> is faster; use g<C-g> when you need word or byte counts

Next

How do I return to normal mode from absolutely any mode in Vim?