From f42c9dabd90d5b2214069a0c32bccc91afc916ab Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 21 Feb 2026 02:42:51 -0500 Subject: [PATCH] fix(preview): prevent preview from re-initializing modified oil buffers Problem: when the preview window opens a directory that already has a loaded oil buffer with unsaved edits, open_preview() unconditionally calls load_oil_buffer() on it. This re-initializes the buffer via view.initialize() -> render_buffer_async(), which re-fetches the directory listing from disk and replaces all buffer lines, destroying the user's pending edits. The mutation parser then can't see the deleted entry in the source buffer, so it produces a COPY action instead of a MOVE. Solution: guard the load_oil_buffer() call in open_preview() with a check for vim.b[filebufnr].oil_ready. Buffers that are already initialized and rendered are not re-loaded, preserving any unsaved modifications the user has made. Closes: stevearc/oil.nvim#632 --- lua/oil/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/oil/init.lua b/lua/oil/init.lua index db454d8..e685dc6 100644 --- a/lua/oil/init.lua +++ b/lua/oil/init.lua @@ -602,7 +602,7 @@ M.open_preview = function(opts, callback) -- If we called open_preview during an autocmd, then the edit command may not trigger the -- BufReadCmd to load the buffer. So we need to do it manually. - if util.is_oil_bufnr(filebufnr) then + if util.is_oil_bufnr(filebufnr) and not vim.b[filebufnr].oil_ready then M.load_oil_buffer(filebufnr) end