From 685cdb4ffa74473d75a1b97451f8654ceeab0f4a Mon Sep 17 00:00:00 2001 From: Alexandros Alexiou Date: Sun, 20 Apr 2025 20:35:57 +0300 Subject: [PATCH] fix: prevent E565 error when opening directories with nvim . (#608) --- lua/oil/util.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/oil/util.lua b/lua/oil/util.lua index ef7cb01..3e70beb 100644 --- a/lua/oil/util.lua +++ b/lua/oil/util.lua @@ -174,8 +174,10 @@ M.rename_buffer = function(src_bufnr, dest_buf_name) -- This will fail if the dest buf name already exists local ok = pcall(vim.api.nvim_buf_set_name, src_bufnr, dest_buf_name) if ok then - -- Renaming the buffer creates a new buffer with the old name. Find it and delete it. - vim.api.nvim_buf_delete(vim.fn.bufadd(bufname), {}) + -- Renaming the buffer creates a new buffer with the old name. + -- Find it and try to delete it, but don't if the buffer is in a context + -- where Neovim doesn't allow buffer modifications. + pcall(vim.api.nvim_buf_delete, vim.fn.bufadd(bufname), {}) if altbuf and vim.api.nvim_buf_is_valid(altbuf) then vim.fn.setreg("#", altbuf) end