-
-
Notifications
You must be signed in to change notification settings - Fork 610
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
Add keymap for closing buffer of file under cursor #3037
Comments
Is that doing what you are after? vim.keymap.set('n', '<C-c>', function()
local filename = require('nvim-tree.api').tree.get_node_under_cursor().absolute_path
vim.cmd({ cmd = 'bdelete', args = { filename } })
end, opts('duffer delete')) You will probably want to check |
Yeah I think so!
About this, would you know how errors are generally reported to the user on nvim-tree? I'm thinking about this case where EDIT: vim.keymap.set("n", "<C-c>", function()
local filename = require("nvim-tree.api").tree.get_node_under_cursor().absolute_path
local buffer_at_filename = vim.fn.bufnr(filename)
if buffer_at_filename == -1 then
notify.error(string.format("No buffer coincides with %s", filename))
return
end
vim.cmd({ cmd = "bdelete", args = { filename } })
end, opts("Close file buffer (if any exist)"))
Do you think this would be a worthy addition to nvim-tree key maps? |
That's a great idea; I think I'd be using that. Let's add it to API. Can we please keep vim nomenclature and add an extra call for wipe: RE error messages, yes please, via notify e.g.
There will be times when vim won't delete the buffer, and will report a message like E89: No write since last change for buffer 1 (add ! to override)
|
Calling the command as a function is a little more robust: vim.cmd.bwipe({ filename, bang = false }) It might also be useful to add an option to the api, something like |
Hey @alex-courtis , sounds good, thanks for the feedback! I have some questions about your comments:
Here do you mean doing something like the code excerpt I added in this comment, but wrapping that into a new API method in
Oh that's true, I hadn't thought of that. Do you have any thoughts on how to handle this? For example, should this not be handled at all (i.e. just call
Sounds good 👍🏼 |
Yup, that would be great. Someone will ask for wipe when they see delete.
If that works we should be fine; vim will effectively If that doesn't work e.g. vim throws an exception, we'll need to wrap it in a pcall and report the error, something like nvim-tree.lua/lua/nvim-tree/events.lua Line 42 in 1ae1c33
|
@alex-courtis @gegoune FYI I've just created a PR for implementing the mentioned API methods: #3040
|
Is this a question?
No
Can this functionality be implemented utilising API?
If I understood correctly, no.
Is your feature request related to a problem? Please describe.
No.
Describe the solution you'd like
I believe it might be useful to add a keymap to close the buffer associated with the tree cursor, if such buffer exists.
If this cannot be done, might be useful to have this implemented in the API so a custom keymap can be added.
Describe alternatives you've considered
As mentioned, adding a custom keymap using an API method that can achieve this, if possible.
Additional context
I've done a draft implementation of this in a PR in my own fork of nvim-tree: GCrispino#1
It adds an API method at
Api.node.close.close_file_buffer
and a keymap to<C-c>
that calls this method.If the maintainers believe this is worth adding, I'd be happy to create a PR here for this
The text was updated successfully, but these errors were encountered: