irongit

feat: ScratchFromCurrent

huncholanehuncholaneauthored
parent 472b26fcommit d02ca0ed79f67d927d6d698c1f9c8c3500d3f53cBrowse files

1 file changed, +16 -0

+16-0nvim/lua/commands.lua
@@ -3,6 +3,22 @@ vim.api.nvim_create_user_command("ToggleDiagnostics", function(_)
33 vim.diagnostic.enable(not diagnostics_enabled)
44 end, { desc = "Toggles Diagnostics" })
55
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+
622 vim.api.nvim_create_autocmd("BufEnter", {
723 pattern = ".env*",
824 callback = function(_)