j-morano/buffer_manager.nvim

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

Closed this issue · 5 comments

Question: what is the best way to map `` to close the window

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.

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.

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

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
})

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