The words Under construction in black text on a yellow background with diagonal black stipes surrounding it
I'm in the process of moving my site. It's still a work in progress. Please excuse the mess and broken links.

Append Text To The End Of A Neovim File Buffer With Lua

TODO: Pull subtitle into page object
Code
local bufnr = 25
local start_line = -1
local end_line = -1
local strict_bounds = false
local lines = { "alfa bravo", "charlie delta" }

vim.api.nvim_buf_set_lines(
  bufnr, start_line, end_line, strict_bounds, lines
)

That will append one line with "alfa bravo" and another with "charlie delta" to the end of the buffer with id number of 25.

Details

Debugging Stuff

I'm moving stuff around right now. All this below is helping me figure out where to put stuff

        -- title

Append Text To The End Of A Neovim File Buffer With Lua

The neovim lua function `nvim_buf_set_lines()`lua` can be
used to append lines to the end of a file buffer 
like this:

-- code
-- lua

local bufnr = 25
local start_line = -1
local end_line = -1
local strict_bounds = false
local lines = { "alfa bravo", "charlie delta" }

vim.api.nvim_buf_set_lines(
  bufnr, start_line, end_line, strict_bounds, lines
)

-- p

That will append one line with "alfa bravo" and 
another with "charlie delta" to the end of the 
buffer with id number of 25.

-- h2

Details

-- list

- `bufnr`` - the buffer number of the
buffer to append the text to. (You can get the 
buffer number of the current buffer with 
`nvim_get_current_buf()`lua` or for a specific
window by the window number with 
`nvim_win_get_buf(WINDOW_NUMBER)`lua`

- `start_line`` - the line on which to start
inserting the text. Negative numbers start
from the end of the file. So, `-1`` starts
at the last line

- `end_line`` - the line to finish writing
the text on. The start line is already
at the end of the file, this also gets 
set to `-1`` since there's nothing after
that point

- `strict_bounds`` - determines if out-of-bounds
attempts to write throw an error. This
is generally set to false unless you have
a specific use case that needs it

- `lines`` - the array of lines to output. 
Each line is its own element in the array


-- categories
-- Neovim 
-- Lua

-- metadata
-- date: 2023-10-20 14:24:45
-- id: 2x2tgvlt
-- site: aws
-- type: post
-- status: published