Close a buffer with an autocommand when the mini.files window is still open #1741
-
Contributing guidelines
Module(s)mini.files QuestionHello, I'm trying to create an autocommand that will execute when opening a specific buffer. It would run a command and close the buffer. What I have right now is this: create_autocmd("BufReadPost", {
group = group,
pattern = { "*.png", "*.jpg", "*.jpeg", "*.gif", "*.webp" },
callback = function(args)
vim.fn.jobstart({ "feh", vim.fn.expand(args.file) })
vim.schedule(function()
if vim.api.nvim_buf_is_valid(args.buf) then
vim.api.nvim_buf_delete(args.buf, { force = true })
end
end)
end,
}) The only problem is that when the specific buffer is opened via mini.files the schedule setup to delete this buffer seams to not work. In fact the |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
This is indeed a weird behavior which sent me to the rabbit whole of debugging the actual source of it. Sparing all the details, it is an Neovim issue: neovim/neovim#20315 . To solve an actual problem (if I understood it correctly) of opening an image not in Neovim as a text file but rather in a dedicated OS viewer, see this part of example mappings. Yes, it is a different mapping instead of a regular If you still want to do this via |
Beta Was this translation helpful? Give feedback.
This is indeed a weird behavior which sent me to the rabbit whole of debugging the actual source of it. Sparing all the details, it is an Neovim issue: neovim/neovim#20315 .
To solve an actual problem (if I understood it correctly) of opening an image not in Neovim as a text file but rather in a dedicated OS viewer, see this part of example mappings. Yes, it is a different mapping instead of a regular
go_in
, but I'd say this is a cleaner approach.If you still want to do this via
go_in
, I'd suggest creating a buffer local mapping in 'mini.files' that will check file name and act depending on its extension: either a CLI call or a regulargo_in()
.