|
| 1 | +-- Create a scratch buffer and a floating window in Neovim using the Lua API |
| 2 | + |
1 | 3 | local api = vim.api |
2 | | -local buf = api.nvim_create_buf(false, true) |
3 | | -local win = vim.api.nvim_open_win(buf, true, |
4 | | - {relative='win', row=3, col=3, width=12, height=3}) |
5 | 4 |
|
| 5 | +-- Create a scratch buffer (not listed, scratch) |
| 6 | +local scratch_buf = api.nvim_create_buf(false, true) |
| 7 | +assert(scratch_buf ~= 0, "Failed to create buffer") |
| 8 | + |
| 9 | +-- Set buffer options (optional) |
| 10 | +api.nvim_buf_set_option(scratch_buf, 'bufhidden', 'wipe') |
| 11 | +api.nvim_buf_set_option(scratch_buf, 'filetype', 'neopilot-scratch') |
| 12 | + |
| 13 | +-- Define window options for a floating window |
| 14 | +local win_opts = { |
| 15 | + relative = 'editor', -- Use 'editor' for global position, or 'win' for relative to window |
| 16 | + row = 3, |
| 17 | + col = 3, |
| 18 | + width = 30, |
| 19 | + height = 8, |
| 20 | + style = 'minimal', -- Optional: Removes window decorations |
| 21 | + border = 'rounded', -- Optional: Adds a border |
| 22 | +} |
| 23 | + |
| 24 | +-- Open the floating window |
| 25 | +local scratch_win = api.nvim_open_win(scratch_buf, true, win_opts) |
| 26 | +assert(scratch_win ~= 0, "Failed to open floating window") |
6 | 27 |
|
| 28 | +-- (Optional) Set some lines in the buffer |
| 29 | +api.nvim_buf_set_lines(scratch_buf, 0, -1, false, { "Hello from NeoPilot!", "This is a floating window." }) |
0 commit comments