Jason Axelson
Jason Axelson

Reputation: 4675

In Vim, how do you get the number of lines in the current file using vimscript?

I'm trying to get the count of lines in the current file using vimscript but I can't figure out how (and google is returning a bunch of crap about showing line numbers).

Upvotes: 75

Views: 61946

Answers (6)

Gowtam Thakur
Gowtam Thakur

Reputation: 59

In vi, i usually get the lines by the below method.

:set number and then shift+g

Upvotes: 3

matty
matty

Reputation: 1643

Pressing ctrl-g will reveal the filename, current line, the line count, your current position as a percentage, and your cursor's current column number.

Upvotes: 62

holytrousers
holytrousers

Reputation: 21

The variable %L already contains the total number of lines.

You could use :echo %L or :set statusline+=%L to append it to the status

Upvotes: 0

serup
serup

Reputation: 3822

when you select an area, then vim shows in corner how many lines you have selected if you have following in your .vimrc file: set statusline=%f\ %l,%c

Upvotes: 2

irin
irin

Reputation: 53

You could also use

wc -l <filename>

Upvotes: 2

kev
kev

Reputation: 161864

You can use line() function:

:echo line('$')

Upvotes: 136

Related Questions