Closed RiteshChepuri closed 4 months ago
Would something like this help?
vim.api.nvim_create_user_command("OilToggle", function()
local current_buf = vim.api.nvim_get_current_buf()
local current_filetype = vim.api.nvim_buf_get_option(current_buf, "filetype")
if current_filetype == "oil" then
-- We use a command to go to the previous buffer
vim.cmd("b#")
else
-- Open oil if not already in an oil buffer
vim.cmd("Oil")
end
end, { nargs = 0 })
Yeah I think it might work. but rather than returning to previous buffer, we can delete the buffer so that it wont appear on buffers list. Thank you.
Here are more concise versions (as getting the filetype does not need two calls).
vim.keymap.set('n', '<Tab>', function()
vim.cmd((vim.bo.filetype == 'oil') and 'bd' or 'Oil')
end)
vim.api.nvim_create_user_command('OilToggle', function()
vim.cmd((vim.bo.filetype == 'oil') and 'bd' or 'Oil')
end, { nargs = 0 })
vim.keymap.set('n', '<Tab>', function()
vim.cmd((vim.bo.filetype == 'oil') and 'bd' or 'Oil')
end)
this works like charm, thank you :)
Did you check existing requests?
Describe the feature
It would be nice to have oil toggle so that we could return to last or previous buffer.
Provide background
Previously when I open a file tree or file explorer like nvim-tree it used have a toggle command so that we could return back to the previous buffer. I made a command to close the netrw plugin when I switched to it. So it would be nice If we have OilToggle command to close the oil buffer.
What is the significance of this feature?
strongly desired
Additional details
No response