17

Is there a command similar to count-words-region to count the total number of lines of a selected region?

1
  • 5
    "The count-words-region command, when called interactively, reports the number of lines, words, and characters in the region. It is a superset of the old count-lines-region, which is now an obsolete alias for it." -- NEWS.24
    – phils
    Commented Mar 20, 2018 at 1:37

2 Answers 2

26

M-= (command count-words-region).

(The region does not even need to be activated, but activating it lets you see it.)

2
  • 1
    How do you get the number of lines from this command? It's displayed but how do you get it in a variable?
    – pierolefou
    Commented Jan 2, 2019 at 0:42
  • some good examples in: emacswiki.org/emacs/WordCount Commented Jan 2, 2019 at 8:37
5

Count lines does the trick, it is defined in simple.el

(count-lines (point-min) (point-max))

Not the answer you're looking for? Browse other questions tagged or ask your own question.