Skip to content

Commit 9b76787

Browse files
authored
feat: add keymap descriptions (#192)
1 parent 538dac1 commit 9b76787

File tree

2 files changed

+106
-25
lines changed

2 files changed

+106
-25
lines changed

after/plugin/Comment.lua

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,54 @@ local K = vim.keymap.set
44
K(
55
'n',
66
'<Plug>(comment_toggle_linewise_count)',
7-
'<CMD>lua require("Comment.api").call("toggle_linewise_count_op")<CR>g@$'
7+
'<CMD>lua require("Comment.api").call("toggle_linewise_count_op")<CR>g@$',
8+
{ desc = 'Comment toggle linewise with count' }
89
)
910
K(
1011
'n',
1112
'<Plug>(comment_toggle_blockwise_count)',
12-
'<CMD>lua require("Comment.api").call("toggle_blockwise_count_op")<CR>g@$'
13+
'<CMD>lua require("Comment.api").call("toggle_blockwise_count_op")<CR>g@$',
14+
{ desc = 'Comment toggle blockwise with count' }
1315
)
1416

1517
-- Toggle mappings
1618
K(
1719
'n',
1820
'<Plug>(comment_toggle_current_linewise)',
19-
'<CMD>lua require("Comment.api").call("toggle_current_linewise_op")<CR>g@$'
21+
'<CMD>lua require("Comment.api").call("toggle_current_linewise_op")<CR>g@$',
22+
{ desc = 'Comment toggle current line' }
2023
)
2124
K(
2225
'n',
2326
'<Plug>(comment_toggle_current_blockwise)',
24-
'<CMD>lua require("Comment.api").call("toggle_current_blockwise_op")<CR>g@$'
27+
'<CMD>lua require("Comment.api").call("toggle_current_blockwise_op")<CR>g@$',
28+
{ desc = 'Comment toggle current block' }
2529
)
2630

2731
-- Operator-Pending mappings
28-
K('n', '<Plug>(comment_toggle_linewise)', '<CMD>lua require("Comment.api").call("toggle_linewise_op")<CR>g@')
29-
K('n', '<Plug>(comment_toggle_blockwise)', '<CMD>lua require("Comment.api").call("toggle_blockwise_op")<CR>g@')
32+
K(
33+
'n',
34+
'<Plug>(comment_toggle_linewise)',
35+
'<CMD>lua require("Comment.api").call("toggle_linewise_op")<CR>g@',
36+
{ desc = 'Comment toggle linewise' }
37+
)
38+
K(
39+
'n',
40+
'<Plug>(comment_toggle_blockwise)',
41+
'<CMD>lua require("Comment.api").call("toggle_blockwise_op")<CR>g@',
42+
{ desc = 'Comment toggle blockwise' }
43+
)
3044

3145
-- Visual-Mode mappings
3246
K(
3347
'x',
3448
'<Plug>(comment_toggle_linewise_visual)',
35-
'<ESC><CMD>lua require("Comment.api").locked.toggle_linewise_op(vim.fn.visualmode())<CR>'
49+
'<ESC><CMD>lua require("Comment.api").locked.toggle_linewise_op(vim.fn.visualmode())<CR>',
50+
{ desc = 'Comment toggle linewise (visual)' }
3651
)
3752
K(
3853
'x',
3954
'<Plug>(comment_toggle_blockwise_visual)',
40-
'<ESC><CMD>lua require("Comment.api").locked.toggle_blockwise_op(vim.fn.visualmode())<CR>'
55+
'<ESC><CMD>lua require("Comment.api").locked.toggle_blockwise_op(vim.fn.visualmode())<CR>',
56+
{ desc = 'Comment toggle blockwise (visual)' }
4157
)

lua/Comment/api.lua

Lines changed: 82 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,44 +248,109 @@ function api.setup(config)
248248
'n',
249249
cfg.toggler.line,
250250
"v:count == 0 ? '<Plug>(comment_toggle_current_linewise)' : '<Plug>(comment_toggle_linewise_count)'",
251-
{ expr = true, remap = true, replace_keycodes = false }
251+
{ expr = true, remap = true, replace_keycodes = false, desc = 'Comment toggle current line' }
252252
)
253253
K(
254254
'n',
255255
cfg.toggler.block,
256256
"v:count == 0 ? '<Plug>(comment_toggle_current_blockwise)' : '<Plug>(comment_toggle_blockwise_count)'",
257-
{ expr = true, remap = true, replace_keycodes = false }
257+
{ expr = true, remap = true, replace_keycodes = false, desc = 'Comment toggle current block' }
258258
)
259259

260-
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)')
261-
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)')
260+
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)', { desc = 'Comment toggle linewise' })
261+
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })
262262

263263
-- VISUAL mode mappings
264-
K('x', cfg.opleader.line, '<Plug>(comment_toggle_linewise_visual)')
265-
K('x', cfg.opleader.block, '<Plug>(comment_toggle_blockwise_visual)')
264+
K(
265+
'x',
266+
cfg.opleader.line,
267+
'<Plug>(comment_toggle_linewise_visual)',
268+
{ desc = 'Comment toggle linewise (visual)' }
269+
)
270+
K(
271+
'x',
272+
cfg.opleader.block,
273+
'<Plug>(comment_toggle_blockwise_visual)',
274+
{ desc = 'Comment toggle blockwise (visual)' }
275+
)
266276
end
267277

268278
-- Extra Mappings
269279
if cfg.mappings.extra then
270-
K('n', cfg.extra.below, '<CMD>lua require("Comment.api").locked.insert_linewise_below()<CR>')
271-
K('n', cfg.extra.above, '<CMD>lua require("Comment.api").locked.insert_linewise_above()<CR>')
272-
K('n', cfg.extra.eol, '<CMD>lua require("Comment.api").locked.insert_linewise_eol()<CR>')
280+
K(
281+
'n',
282+
cfg.extra.below,
283+
'<CMD>lua require("Comment.api").locked.insert_linewise_below()<CR>',
284+
{ desc = 'Comment insert below' }
285+
)
286+
K(
287+
'n',
288+
cfg.extra.above,
289+
'<CMD>lua require("Comment.api").locked.insert_linewise_above()<CR>',
290+
{ desc = 'Comment insert above' }
291+
)
292+
K(
293+
'n',
294+
cfg.extra.eol,
295+
'<CMD>lua require("Comment.api").locked.insert_linewise_eol()<CR>',
296+
{ desc = 'Comment insert end of line' }
297+
)
273298
end
274299

275300
-- Extended Mappings
276301
if cfg.mappings.extended then
277302
-- NORMAL mode extended
278-
K('n', 'g>', '<CMD>lua require("Comment.api").call("comment_linewise_op")<CR>g@')
279-
K('n', 'g>c', '<CMD>lua require("Comment.api").call("comment_current_linewise_op")<CR>g@$')
280-
K('n', 'g>b', '<CMD>lua require("Comment.api").call("comment_current_blockwise_op")<CR>g@$')
303+
K(
304+
'n',
305+
'g>',
306+
'<CMD>lua require("Comment.api").call("comment_linewise_op")<CR>g@',
307+
{ desc = 'Comment region linewise' }
308+
)
309+
K(
310+
'n',
311+
'g>c',
312+
'<CMD>lua require("Comment.api").call("comment_current_linewise_op")<CR>g@$',
313+
{ desc = 'Comment current line' }
314+
)
315+
K(
316+
'n',
317+
'g>b',
318+
'<CMD>lua require("Comment.api").call("comment_current_blockwise_op")<CR>g@$',
319+
{ desc = 'Comment current block' }
320+
)
281321

282-
K('n', 'g<', '<CMD>lua require("Comment.api").call("uncomment_linewise_op")<CR>g@')
283-
K('n', 'g<c', '<CMD>lua require("Comment.api").call("uncomment_current_linewise_op")<CR>g@$')
284-
K('n', 'g<b', '<CMD>lua require("Comment.api").call("uncomment_current_blockwise_op")<CR>g@$')
322+
K(
323+
'n',
324+
'g<',
325+
'<CMD>lua require("Comment.api").call("uncomment_linewise_op")<CR>g@',
326+
{ desc = 'Uncomment region linewise' }
327+
)
328+
K(
329+
'n',
330+
'g<c',
331+
'<CMD>lua require("Comment.api").call("uncomment_current_linewise_op")<CR>g@$',
332+
{ desc = 'Uncomment current line' }
333+
)
334+
K(
335+
'n',
336+
'g<b',
337+
'<CMD>lua require("Comment.api").call("uncomment_current_blockwise_op")<CR>g@$',
338+
{ desc = 'Uncomment current block' }
339+
)
285340

286341
-- VISUAL mode extended
287-
K('x', 'g>', '<ESC><CMD>lua require("Comment.api").locked.comment_linewise_op(vim.fn.visualmode())<CR>')
288-
K('x', 'g<', '<ESC><CMD>lua require("Comment.api").locked.uncomment_linewise_op(vim.fn.visualmode())<CR>')
342+
K(
343+
'x',
344+
'g>',
345+
'<ESC><CMD>lua require("Comment.api").locked.comment_linewise_op(vim.fn.visualmode())<CR>',
346+
{ desc = 'Comment region linewise (visual)' }
347+
)
348+
K(
349+
'x',
350+
'g<',
351+
'<ESC><CMD>lua require("Comment.api").locked.uncomment_linewise_op(vim.fn.visualmode())<CR>',
352+
{ desc = 'Uncomment region linewise (visual)' }
353+
)
289354
end
290355
end
291356

0 commit comments

Comments
 (0)