-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
ZB: command to delete buffer without closing the window #2434
Comments
That isn't necessary at all. The hack I use switches to the next valid buffer (or creates a new empty one), then deletes the original. I'm planning to release it as part of a plugin... |
Yes, I know. But the idea of adding a new core command for this doesn't sound appealing. Details would be welcome though. |
|
@justinmk A whole terminal was added along with autocommands, a command, and a Terminal class. This is incredibly light weight in comparison. And surprisingly, @splinterofchaos |
Why not simply implement this as a buffer option? |
I'm talking about the UI, not the technical cost, and in proportion to the benefit. The technical and UI cost of
So what about someone who wants to
Users will still need to wrap that option in a command, so it doesn't gain anything over the current situation. |
But this does:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Really simple, no need for a separate option just to achieve that 😄 |
Not entirely true, when you have two windows open displaying the buffer you want to delete, 'bd' deletes the buffer (and both windows), while 'setl bufhidden=delete | bnext' only goes to the next buffer in the current window and nothing more. Edit: Of course the buffer is still being marked as bufhidden=delete, so :bnext in the other window will delete the buffer then. |
@HarmtH I've realized this as I've been writing this plugin for the past 20 minutes. It seems it's more nuance than I thought. You have to make sure no windows are pointing at the buffer. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@weichm What proposed feature? Nothing concrete was actually proposed. The request can't be achieved with just one new command, see here. Can't be just one new option either. Should we add 4 new options/commands for this? Something that might work: a global option that says "always preserve windows when deleting/wiping/unloading buffers". |
Only if you delete the buffer. You can exit terminal-mode with CTRL-\ CTRL-N instead. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Oh wow, I got a notification on this issue today and I didn't realize that I was the original creator. FYI, I can do this with lua and it's pretty much exactly what I want. Now that I'm on the neovim team, maybe we can add this to the core, but here it is for anyone who's interested: local api = vim.api
local function nvim_loaded_buffers()
local result = {}
local buffers = api.nvim_list_bufs()
for _, buf in ipairs(buffers) do
if api.nvim_buf_is_loaded(buf) then
table.insert(result, buf)
end
end
return result
end
-- Kill the target buffer (or the current one if 0/nil)
function buf_kill(target_buf, should_force)
if not should_force and vim.bo.modified then
return api.nvim_err_writeln('Buffer is modified. Force required.')
end
local command = 'bd'
if should_force then command = command..'!' end
if target_buf == 0 or target_buf == nil then
target_buf = api.nvim_get_current_buf()
end
local buffers = nvim_loaded_buffers()
if #buffers == 1 then
api.nvim_command(command)
return
end
local nextbuf
for i, buf in ipairs(buffers) do
if buf == target_buf then
nextbuf = buffers[(i - 1 + 1) % #buffers + 1]
break
end
end
api.nvim_set_current_buf(nextbuf)
api.nvim_command(table.concat({command, target_buf}, ' '))
end This is how I use it. " normal kill
nnoremap <a-c> <Cmd>lua buf_kill(0)<CR>
" force kill
nnoremap <a-s-c> <Cmd>lua buf_kill(0, true)<CR> It will unload the current buffer and switch to another buffer without closing the window. E: Also donate your money to the neovim team or your favorite charity instead. |
This comment has been minimized.
This comment has been minimized.
It's not really a hack for my use case where I want to have the option to either close the window or not. Since you want it to be some kind of default mode option @kasymovga, I recommend opening a new issue, because I would consider this one to be closed. |
This would not be implemented as an option, that would break plugins. Instead it could be a new command, I'm thinking |
For the Ex command, i would suggest adding a modifier comparable to Then it won't only be useful for |
All other solutions I know of are hacks that kinda work (usually by creating a new split and then deleting the buffer in that window, and attempting to cover all possible cases for this), but intrinsic support for this would be greatly appreciated.
The text was updated successfully, but these errors were encountered: