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

Vim

Vim Problem Overview


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).

Vim Solutions


Solution 1 - Vim

You can use line() function:

:echo line('$')

Solution 2 - Vim

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.

Solution 3 - Vim

You could also use

wc -l <filename>

Solution 4 - Vim

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

Solution 5 - Vim

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJason AxelsonView Question on Stackoverflow
Solution 1 - VimkevView Answer on Stackoverflow
Solution 2 - VimmattyView Answer on Stackoverflow
Solution 3 - VimirinView Answer on Stackoverflow
Solution 4 - VimserupView Answer on Stackoverflow
Solution 5 - VimholytrousersView Answer on Stackoverflow