As title. I want to check that a buffer is not shown in any tabs. How to do so?
2 Answers
Buffer is called "hidden" if it's
- Loaded
- Not shown in any window
:echo bufloaded(N) && win_findbuf(N)->empty()
or
:echo bufexists(N) && getbufinfo(N)[0].hidden
-
Additional one: Do you know the api to do the same in Lua(for NeoVim)? While your current one is really helpful since now I really understand
hidden
mean and I can still use NeoVim's API to write VimScript. Commented Jan 10, 2022 at 18:05 -
@job_start Neovim API is documented in
:h api.txt
. AFAIR, there's none.– MattCommented Jan 10, 2022 at 18:21
FYI: You can use the following APIs in Lua:
local is_hidden_buffer = vim.api.nvim_buf_is_loaded(buf)
and vim.api.nvim_buf_get_option(buf, 'buflisted')