Buffers and Windows
Manipulate the editor.
Buffers, Windows, Tabs
Neovim separates content from display. A buffer holds text in memory; a window is a viewport onto a buffer; a tabpage is a layout of windows.
One buffer can appear in many windows. Plugins manipulate these handles, which are integers, through the nvim_buf_* and nvim_win_* API families.
local buf = vim.api.nvim_get_current_buf()
local win = vim.api.nvim_get_current_win()
print(buf, win)Reading Buffer Lines
nvim_buf_get_lines(buf, start, end_, strict) returns lines as a list. Indices are zero-based and end-exclusive; pass -1 as the end to reach the last line.
Setting strict_indexing to false tolerates out-of-range indices instead of erroring.
local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false)
print('line count: ' .. #lines)All lessons in this course
- The Neovim Lua API
- Commands and Keymaps
- Buffers and Windows
- Packaging a Plugin