Is there a way to get only the number of lines in the Vim buffer, not necessarily the current one?
With line('$') you can get the number of the last line of the current buffer, therefore, the number of lines. Using getbufline({expr}, 1 , '$') you can get a list of lines of the buffer line specified by {expr} , then the size of the list is the number of lines.
Using getbufline has the overhead of copying the entire file in memory just to get the number of lines it contains. line does the job, but only works for the current buffer.
This is supposed to be done from a script, and not interactively and with minimal overhead, as is possible with line('$') .
source share