nvim-tree / nvim-tree.lua

A file explorer tree for neovim written in lua
Other
7.08k stars 606 forks source link

Don't Close Window On fs.remove() When Last Buffer In Window #2861

Open siduck opened 2 months ago

siduck commented 2 months ago

Problem When there's just 1 window opened along with nvimtree, then deleting its file from tree, would make nvimtree become fullscreen

Desired behavior Nvimtree should open unamed buf ( enew ) and then delete, this will maintain the win layout!

 actions = {
    remove_file = {
      open_unamed_buf = true,
    },
  },

Possible solutions with edgecases

The code must be run only when the user presses "y"

Case 1

If there's just 1 listed buffer and its the active window

alex-courtis commented 2 months ago

Discussions: https://github.com/NvChad/NvChad/issues/2950

TL;DR: this is possible but will be tricky from a functional and technical perspective.

siduck commented 2 months ago

image

cant we create an unnamed buf and place it in the window of the buffer which is getting deleted :thinking:

alex-courtis commented 2 months ago

cant we create an unnamed buf and place it in the window of the buffer which is getting deleted 🤔

That sounds sensible.

siduck commented 2 months ago

so would this be added to nvimtree or the user has to add in his config? I tried with an autocmd


vim.api.nvim_create_autocmd("BufDelete", {
  callback = function()
    local cur_buf = vim.api.nvim_get_current_buf()
    local cur_ft = vim.bo[cur_buf].ft

    if cur_ft == "NvimTree" and #vim.fn.getbufinfo { buflisted = 1 } == 1 then
      vim.cmd "bn"
      vim.cmd "enew"
    end
  end,
})

but this closes nvimtree window too, no idea why

alex-courtis commented 2 months ago

This is something that should go into nvim-tree itself. It needs the internals of remove-file.lua