Not for normies
feat: ScratchFromCurrent
1 file changed, +16 -0
+16-0nvim/lua/commands.lua
| @@ -3,6 +3,22 @@ vim.api.nvim_create_user_command("ToggleDiagnostics", function(_) | ||
| 3 | 3 | vim.diagnostic.enable(not diagnostics_enabled) |
| 4 | 4 | end, { desc = "Toggles Diagnostics" }) |
| 5 | 5 | |
| 6 | +vim.api.nvim_create_user_command("ScratchFromCurrent", function() | |
| 7 | + -- create new scratch buffer | |
| 8 | + vim.cmd("enew") | |
| 9 | + vim.bo.buftype = "nofile" | |
| 10 | + vim.bo.bufhidden = "hide" | |
| 11 | + vim.bo.swapfile = false | |
| 12 | + vim.bo.buflisted = false | |
| 13 | + -- fill it with the contents of the previous buffer | |
| 14 | + local prev = vim.fn.bufnr("#") -- previous buffer | |
| 15 | + if prev ~= -1 then | |
| 16 | + local lines = vim.api.nvim_buf_get_lines(prev, 0, -1, false) | |
| 17 | + vim.api.nvim_buf_set_lines(0, 0, -1, false, lines) | |
| 18 | + end | |
| 19 | + vim.notify("📄 Copied current buffer into a scratch buffer") | |
| 20 | +end, { desc = "Copy current buffer contents into scratch" }) | |
| 21 | + | |
| 6 | 22 | vim.api.nvim_create_autocmd("BufEnter", { |
| 7 | 23 | pattern = ".env*", |
| 8 | 24 | callback = function(_) |