diff --git a/lua/nvim-tree/actions/node/open-file.lua b/lua/nvim-tree/actions/node/open-file.lua index de43416eac1..600f8656fbb 100644 --- a/lua/nvim-tree/actions/node/open-file.lua +++ b/lua/nvim-tree/actions/node/open-file.lua @@ -198,7 +198,15 @@ local function open_file_in_tab(filename) if M.relative_path then filename = utils.path_relative(filename, vim.fn.getcwd()) end - vim.cmd("tabe " .. vim.fn.fnameescape(filename)) + vim.cmd.tabnew() + vim.bo.bufhidden = "wipe" + -- Following vim.fn.tabnew the # buffer may be set to the tree buffer. There is no way to clear the # buffer via vim.fn.setreg as it requires a valid buffer. Clear # by setting it to a new temporary scratch buffer. + if utils.is_nvim_tree_buf(vim.fn.bufnr("#")) then + local tmpbuf = vim.api.nvim_create_buf(false, true) + vim.fn.setreg("#", tmpbuf) + vim.api.nvim_buf_delete(tmpbuf, { force = true }) + end + vim.cmd.edit(vim.fn.fnameescape(filename)) end local function drop(filename)