You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reacted by Simon Ashton, Ethan Rutt, Fabian Winter, ArturoGJ, James Han, Lyle Hanson, Pål Sivertsen, mpachin, Matheus Ferraz, Haruya Ishikawa and 1 more
I landed here when I found which-key.nvim was causing Comment.nvim gcc to not work. I'm still trying to solve the issue.
Which warning did you get from which-key? How does your snippet remove the warning? I see that "gc" and "gb" keymaps in normal mode are removed. Those keymaps are added back via wk.add()?
Yes because the the mappings in Comment.nvim are ordinary mappings rather than groups. This conflicts with nested mappings. This snippet removes the bad mappings and replaces them with groups, which doesn't conflict.
Perhaps I misunderstood something. require('Comment').setup() sets the default keymaps for Comment.nvim that include gc and gb. Then vim.keymap.del("n", "gc") and vim.keymap.del("n", "gb") delete those default keymaps. For those keymaps to work again, wouldn't each keymap in wk.add() need additional RHS parameters?
Some RHS parameters from Comment.txt at around line 267:
Usage: ~
>lua
-- Toggle current line or with count
vim.keymap.set('n', 'gcc', function()
return vim.v.count == 0
and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)'
end, { expr = true })
-- Toggle in Op-pending mode
vim.keymap.set('n', 'gc', '<Plug>(comment_toggle_linewise)')
-- Toggle in VISUAL mode
vim.keymap.set('x', 'gc', '<Plug>(comment_toggle_linewise_visual)')
<
Those keymaps don't need to "work" since they're supposed to be group-keymaps. We don't want to run those plug-commands. We want to run nothing and set the which-key heading. gc should do this:
Some RHS parameters from Comment.txt at around line 267:
@NeilGirdhar , thanks for taking the time to explain. I'll summarize to help others new to which-key, nvim, or Comment.nvim save time down the rabbit hole.
I made many configuration changes during my experiments, including using gb and gc as keymaps, not just group-keymaps! So in my head, I kept thinking if they get deleted, they can't be used again. For the default settings, Comment.nvim sets gc and gb as "ordinary mappings rather than groups." gcc and gbc are "ordinary" keymaps. Therefore, deleting gc and gb, and re-adding them as group-keymap via wk.add() removes the warnings, and gcc and gbc continue to work.
You got it! Do you feel like trying to get a pull request through to remove these from Comment.nvim? Maybe even (somehow, I have no idea how) make it add the group bindings if which-key is installed? That would clean this up for all users 😄
Having Comment.nvim detect if which-key is in use and addressing the issue within the Comment.nvim's source code would be idea. I am still new to Lua and nvim to be able to get a pull request though to fix this.
I'm curious if either of you updated your which-key config for v3 — I found the :checkhealth which-key warnings for all my mappings (it was complaining about others besides Comment.nvim) went away after I updated the config as described here: https://github.com/folke/which-key.nvim#-installation.
@bak Which installation option are you talking about? I get
checking for overlapping keymaps ~
- WARNING In mode `n`, <gc> overlaps with <gcO>, <gcc>, <gco>, <gcA>:
- <gc>: Comment toggle linewise
- <gcO>: Comment insert above
- <gcc>: Comment toggle current line
- <gco>: Comment insert below
- <gcA>: Comment insert end of line
- WARNING In mode `n`, <gb> overlaps with <gbc>:
- <gb>: Comment toggle blockwise
- <gbc>: Comment toggle current block
- OK Overlapping keymaps are only reported for informational purposes.
This doesn't necessarily mean there is a problem with your config.
Yeah sorry I don't know exactly the change that fixed things, but I was getting the same output as you, and found this thread, but noticed that which-key released 3.0 about the time of your first post and went to check out their README to see what might have changed. I replaced what I had with their suggested config:
{
"folke/which-key.nvim",
event = "VeryLazy",
opts = {
-- your configuration comes here
-- or leave it empty to use the default settings
-- refer to the configuration section below
},
keys = {
{
"<leader>?",
function()
require("which-key").show({ global = false })
end,
desc = "Buffer Local Keymaps (which-key)",
},
},
}
@NeilGirdhar If add the lines in my nvim config, I cannot comment 3 lines by typing "gc2j" (This is like an example). There is a trade-off, right?
I'm also investigating this warning from :checkhealth which-key. However, for Comment.nvim, there is a reason to set the keymap "gc" and "gb". In the meantime, I couldn't find a way to solve this warning by changing code in Comment.nvim :-/
@Edditoria You are right! Any ideas on what a good resolution would be? Can which-key be improved to show a menu entry for "movement commands do this"?
Activity
thomastthai commentedon Oct 1, 2024
I landed here when I found which-key.nvim was causing Comment.nvim
gccto not work. I'm still trying to solve the issue.Which warning did you get from which-key? How does your snippet remove the warning? I see that "gc" and "gb" keymaps in normal mode are removed. Those keymaps are added back via
wk.add()?NeilGirdhar commentedon Oct 1, 2024
Yes because the the mappings in
Comment.nvimare ordinary mappings rather than groups. This conflicts with nested mappings. This snippet removes the bad mappings and replaces them with groups, which doesn't conflict.thomastthai commentedon Oct 2, 2024
Perhaps I misunderstood something.
require('Comment').setup()sets the default keymaps forComment.nvimthat includegcandgb. Thenvim.keymap.del("n", "gc")andvim.keymap.del("n", "gb")delete those default keymaps. For those keymaps to work again, wouldn't each keymap inwk.add()need additional RHS parameters?Some RHS parameters from Comment.txt at around line 267:
NeilGirdhar commentedon Oct 2, 2024
Those keymaps don't need to "work" since they're supposed to be group-keymaps. We don't want to run those plug-commands. We want to run nothing and set the which-key heading.
gcshould do this:Yes, those look like the problematic lines.
thomastthai commentedon Oct 2, 2024
For those coming here from the future, the which-key warnings @NeilGirdhar may be referring to are from
:checkhealth which-keyare similar to:I changed my keymaps for
Comment.nvimto use my key which is , which may be different than yours.thomastthai commentedon Oct 2, 2024
@NeilGirdhar , thanks for taking the time to explain. I'll summarize to help others new to
which-key,nvim, orComment.nvimsave time down the rabbit hole.I made many configuration changes during my experiments, including using
gbandgcas keymaps, not just group-keymaps! So in my head, I kept thinking if they get deleted, they can't be used again. For the default settings,Comment.nvimsetsgcandgbas "ordinary mappings rather than groups."gccandgbcare "ordinary" keymaps. Therefore, deletinggcandgb, and re-adding them as group-keymap viawk.add()removes the warnings, andgccandgbccontinue to work.NeilGirdhar commentedon Oct 2, 2024
You got it! Do you feel like trying to get a pull request through to remove these from Comment.nvim? Maybe even (somehow, I have no idea how) make it add the group bindings if which-key is installed? That would clean this up for all users 😄
thomastthai commentedon Oct 3, 2024
Having
Comment.nvimdetect ifwhich-keyis in use and addressing the issue within theComment.nvim's source code would be idea. I am still new to Lua and nvim to be able to get a pull request though to fix this.bak commentedon Oct 6, 2024
I'm curious if either of you updated your
which-keyconfig for v3 — I found the:checkhealth which-keywarnings for all my mappings (it was complaining about others besidesComment.nvim) went away after I updated the config as described here: https://github.com/folke/which-key.nvim#-installation.NeilGirdhar commentedon Oct 6, 2024
@bak Which installation option are you talking about? I get
without the above configuration.
bak commentedon Oct 8, 2024
Yeah sorry I don't know exactly the change that fixed things, but I was getting the same output as you, and found this thread, but noticed that which-key released
3.0about the time of your first post and went to check out their README to see what might have changed. I replaced what I had with their suggested config:and haven't had a problem since
NeilGirdhar commentedon Oct 8, 2024
I don't think that works. Try removing the config and see if the errors reappear. If not, then this isn't really a fix.
Edditoria commentedon Mar 1, 2025
It will lose the ability of motions, e.g.
gc2jto comment 3 lines.NeilGirdhar commentedon Mar 1, 2025
What do you mean?
Edditoria commentedon Mar 1, 2025
@NeilGirdhar If add the lines in my nvim config, I cannot comment 3 lines by typing "gc2j" (This is like an example). There is a trade-off, right?
I'm also investigating this warning from
:checkhealth which-key. However, for Comment.nvim, there is a reason to set the keymap "gc" and "gb". In the meantime, I couldn't find a way to solve this warning by changing code in Comment.nvim :-/NeilGirdhar commentedon Mar 1, 2025
@Edditoria You are right! Any ideas on what a good resolution would be? Can which-key be improved to show a menu entry for "movement commands do this"?
Fix checkhealth which-key warning