Get buffer's line count and check for emptiness

16 views
Skip to first unread message

Lifepillar

unread,
Jan 5, 2025, 8:09:19 AM (3 days ago) Jan 5
to vim...@googlegroups.com
var linecount = getbufinfo(bufnr)[0].linecount

I also need to check whether a buffer is empty, which I do like this:

var is_empty = linecount == 1 && empty(getbufoneline(bufnr, 1))

I'm wondering: is there any simpler way to perform the two tasks above
that I'm missing?

Thanks,
Life.


Salman Halim

unread,
Jan 5, 2025, 8:13:56 AM (3 days ago) Jan 5
to vim...@googlegroups.com

line('$') == 1 to see if it's just one line
getline('1') == '' to see if that line is completely empty

Salman

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/vim_use/vle098%24an9%241%40ciao.gmane.io.

Salman Halim

unread,
Jan 5, 2025, 8:16:04 AM (3 days ago) Jan 5
to vim...@googlegroups.com

I may have missed the part where you're not checking the current buffer (the bufnr bit). Not sure of an easier way than what you have to check if another buffer is empty.

Salman

Lifepillar

unread,
Jan 5, 2025, 4:03:11 PM (2 days ago) Jan 5
to vim...@googlegroups.com
On 2025-01-05, Salman Halim <salma...@gmail.com> wrote:
> I may have missed the part where you're not checking the current buffer
> (the bufnr bit). Not sure of an easier way than what you have to check if
> another buffer is empty.

Thanks. For some reason the beginning of my message got cut away. The
context is that I need to check in a Vim script function whether
a buffer passed as a parameter to the function is empty or how many
lines it has.

Life.

Reply all
Reply to author
Forward
0 new messages