From de3cd1fb32077972ae5e593f7697dd6d4947c5df Mon Sep 17 00:00:00 2001 From: akioweh <0@akioweh.com> Date: Sat, 16 May 2026 05:33:55 +0100 Subject: [PATCH] fix: check buffer validity in autocmd to prevent keymap.set() throwing the buffer that triggered the autocmd could be gone by the time vim.schedule runs keymap.set, e.g. with transient buffers created by nvim_get_option_value --- lua/lazyvim/config/autocmds.lua | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lua/lazyvim/config/autocmds.lua b/lua/lazyvim/config/autocmds.lua index a0b058a6..33c4f21d 100644 --- a/lua/lazyvim/config/autocmds.lua +++ b/lua/lazyvim/config/autocmds.lua @@ -74,6 +74,10 @@ vim.api.nvim_create_autocmd("FileType", { callback = function(event) vim.bo[event.buf].buflisted = false vim.schedule(function() + -- without this, vim.keymap.set below may throw on transient buffers + if not vim.api.nvim_buf_is_valid(event.buf) then + return + end vim.keymap.set("n", "q", function() vim.cmd("close") pcall(vim.api.nvim_buf_delete, event.buf, { force = true })