Make it easier to disable mappings
Hi, thanks for what seems like a great plugin.
It'd be nice if there was an easy way of disabling mappings. Specifically, after installing the plugin, I expected one of:
{
"CopilotC-Nvim/CopilotChat.nvim",
...
opts = {
mappings = {}
}
},
or
{
"CopilotC-Nvim/CopilotChat.nvim",
...
opts = {
mappings = false
}
},
to do so, or even
opts = {
mappings = {
complete = {
},
close = {
},
reset = {
},
submit_prompt = {
},
toggle_sticky = {
},
clear_stickies = {
},
accept_diff = {
},
jump_to_diff = {
},
quickfix_answers = {
},
quickfix_diffs = {
},
yank_diff = {
},
show_diff = {
},
show_info = {
},
show_context = {
},
show_help = {},
}
},
but none of the above appear to be enough, and one has to spell out normal and insert seemingly for each mapping.
Besides being verbose, this is also fragile, as not having something like mappings = {} means if the plugin adds a new mapping, that mapping will "silently" get mapped for me rather than never adding any mappings.
Would there be support for making that work in some way? I.e. making there be a way to say both "map nothing" and "map only these things"?
(Relatedly, I think whether Neovim plugins should enable any mappings by default is itself a matter of debate -- I certainly understand plugins that do so at this point even though I don't like it myself -- but even when doing so I think one or two of the default mappings are humbly slightly questionable, particularly gj which quashes an important motion in normal mode, and arguably gi as well, along with one or two otherg mappings which are unlikely to be used in a chat buffer and yet still quite jarring when one does use them and sees some other thing happen. My personal intention is to move all of them to <localleader> mappings.).
Apologies if I've missed an existing way of doing this and thanks again for the plugin!
Something like {} can never work because the configs are always merged together, but false should def be supported, the plugin even already supports it on some other places so probably just missed adding proper check here as well. I can look at fixing this tomorrow.
And for default mappings, I agree on global mappings, that is why those are never set here, but for the chat buffer the mappings are mostly mandatory for the chat to function so normal expectation from user is to just change keys, but allowing to disable the mappings with false is understandable.
Even though not sure if you can achieve avoiding plugin silently mapping new mappings, because you cant really map bunch of them with normal vim.keymap.set and disable the default mappings completely as the callbacks expect to be called with source argument and that is not exposed at all outside of the inner plugin implementation (even though I was thinking about potentionally exposing it)
Seems reasonable, thanks for the response, will have a look out for any changes you have in mind!
Setting a mapping to an empty string disables it
mappings = {
complete = {
insert = "<Tab>",
},
close = {
normal = "<leader>x",
insert = "",
},
Empty strings works. IMO the only change needed from this issue is to update the docs and provide this example.
Well the original issue talks about having to do it for every single mapping, and also option to disable all the default mappings at once. I added option so complete = false works, I tried to look at disabling all mappings at once but I think checking for that everywhere is kinda annoying for little benefit, but leaving this issue open for now either way, at worst I can just close it at some point with wontfix, but its still valid.
Now that default config is freely modifiable this is now pretty easy to do by manipulating it directly (require('CopilotChat.config).do_whatever = {})