j-morano / buffer_manager.nvim

A simple plugin to easily manage Neovim buffers.
MIT License
232 stars 12 forks source link

Question: what is the best way to map `<C-c>` to close the window #9

Closed strash closed 1 year ago

j-morano commented 1 year ago

Do you mean to close the popup menu? If that's what you mean, I think this way is the right way:

vim.keymap.set({ 't', 'n' }, '<C-c>', require("buffer_manager.ui").toggle_quick_menu, {noremap = true})

On the other hand, if you mean to close the buffer, this way:

require("buffer_manager").setup({
  select_menu_item_commands = {
    c = {
      key = "<C-c>",
      command = "bd"
    }
  },
})

Lastly, if you mean to close a "vim window", you cannot do it using the plugin.

strash commented 1 year ago

Sorry I didn't specify which window I meant, it's the popup window. Thought I can assign a command inside the plugin config that would only work when the buffer manager is active. Thanks for your examples, I think I now know what to do.

j-morano commented 1 year ago

Okay. Even so, if you consider that it can't be done, let me know.

strash commented 1 year ago

I did this and it works as expected:

vim.api.nvim_create_autocmd({
    "FileType",
}, {
    callback = function(args)
        if args.match == "buffer_manager" then
            vim.keymap.set({ "i", "n" }, "<C-c>", function() require("buffer_manager.ui").toggle_quick_menu() end, { buffer = true })
        end
    end,
    group = group
})
j-morano commented 1 year ago

Yes, it is probably the best way to do it. Thanks for sharing.