Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

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:

Code

nvim_win_get_buf(WINDOW_NUMBER)

Where `WINDOW_NUMBER`` 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:

Code

:echo nvim_win_get_buf(WINDOW_NUMBER)

The Current Window Number

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

Code

nvim_get_current_win()

Which is used like this on the command line

Code

:echo nvim_get_current_win()