Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

vim

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

like image 775
Jason Axelson Avatar asked Nov 14 '12 03:11

Jason Axelson


People also ask

How do I jump a line number in vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.

How do I go to a specific line number in vi editor?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.

What vim command allows you to move to the first line in the current file?

Press ^ to move the cursor to the start of the current line. Press $ to move the cursor to the end of the current line.


1 Answers

You can use line() function:

:echo line('$') 
like image 179
kev Avatar answered Sep 22 '22 17:09

kev