Count words and lines

4.1
(69)

Here’s a tip that I always forget about but is useful if you can internalize it: Press g followed by <ctrl-g> to get information about the current cursor position, including the current line and total number of lines plus the total number of words in the file and more.

When is this useful? A few places for me:

  • Writing prose or articles and needing to aim for a certain number of words? Press g <ctrl-g> to get the current word count.
  • Writing code but have line number restrictions in your software quality tools? Press g <ctrl-g> to see the total number of lines in the file.

After pressing g <ctrl-g>, you’ll see something like this in the Vim command line:

Col 22 of 44; Line 19 of 22; Word 70 of 74; Byte 568 of 602

Check out the demo gif below. First I’m positioned in the bottom split and I press g <ctrl-g> to get the count of words in the Markdown file: 267 words, the essay isn’t long enough! Next, I press <ctrl-w> k to move to the top split and press g <ctrl-g> to get the line count on Fugitive: 6,439 lines, wow this plugin is huge!

How useful was this tip?

Average rating 4.1 / 5. Vote count: 69

No votes so far! Be the first to rate this tip.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Written by

Colin Bartlett

105 Posts

Vim enthusiast and software developer for more than 20 years.
View all posts