Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature request: suppress "no longer available" #207

Open
1 task done
anuramat opened this issue Oct 28, 2023 · 2 comments
Open
1 task done

feature request: suppress "no longer available" #207

anuramat opened this issue Oct 28, 2023 · 2 comments
Labels
enhancement New feature or request P1 May get worked on if I get free time. PRs welcome

Comments

@anuramat
Copy link

Did you check existing requests?

  • I have searched the existing issues

Describe the feature

When deleting a file that is open, the corresponding buffer is still loaded and you get a "no longer available" message.
It would be nice to have an option that would automatically delete buffers that correspond to deleted files, and save+reopen buffers for the moved files.

Provide background

Moving/deleting open files is annoying atm.

Additional details

Got the idea from tpope/vim-eunuchs :Remove

@anuramat anuramat added the enhancement New feature or request label Oct 28, 2023
@stevearc
Copy link
Owner

stevearc commented Nov 1, 2023

Yeah, this would be possible. The current behavior intentionally leaves the buffers in-place as sort of an extra protection from data loss, but we could potentially add another config option to remove those buffers. Will add to my backlog

@stevearc stevearc added the P1 May get worked on if I get free time. PRs welcome label Dec 1, 2023
@windowsrefund
Copy link

windowsrefund commented Dec 22, 2024

Astrocommunity gets this done here. My lua-fu is too weak so my struggles to piece together something distro-agnostic are real Maybe someone can improve on this?

vim.api.nvim_create_autocmd("User", {
  desc = "Close buffers when files are deleted in Oil",
  pattern = "OilActionsPost",
  callback = function(args)
    if args.data.err then return end
    for _, action in ipairs(args.data.actions) do
      if action.type == "delete" then
        local _, path = require("oil.util").parse_url(action.url)
        local bufnr = vim.fn.bufnr(path)
        if bufnr ~= -1 then vim.cmd.bwipeout { bufnr, bang = true } end
      end
    end
  end,
})

This is sorta working but I am always left with an orphaned buffer with foo.txt loaded.

echo foo > {foo,bar}.txt
vi {foo,bar}.txt

With the 2 buffers now open, I now:

  1. Run Oil
  2. dd foo.txt and bar.txt
  3. :w and confirm

The bar.txt buffer is removed but the other is still showing despite foo.txt being deleted from the directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request P1 May get worked on if I get free time. PRs welcome
Projects
None yet
Development

No branches or pull requests

3 participants