Home

Get The Buffer Number Of A Buffer In A Neovim Window With Lua

Getting The Buffer Number

Use this to get the buffer number of the buffer in a specific window:

lua
nvim_win_get_buf(WINDOW_NUMBER)

Where [TODO: Code shorthand span ] is the number of the window you want to get the buffer number for. It can be set to zero to get the buffer number of the current window.

To see the value on the command line, use:

lua
:echo nvim_win_get_buf(WINDOW_NUMBER)

The Current Window Number

You can find the window number of the current window with:

lua
nvim_get_current_win()

Which is used like this on the command line

lua
:echo nvim_get_current_win()
~ fin ~