diff --git a/README.md b/README.md index 0f8454cd..fcccb44d 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,10 @@ Following are the **default** config for the [`setup()`](#setup). If you want to basic = true, ---Extra mapping; `gco`, `gcO`, `gcA` extra = true, + ---Operator-pending mapping; `gc` gc[count]{motion}` + line = true, + ---Operator-pending mapping; `gbc` `gb[count]{motion}` + block = true, }, ---Function to call before (un)comment pre_hook = nil, diff --git a/doc/Comment.txt b/doc/Comment.txt index 2bf2b641..cf574bfe 100644 --- a/doc/Comment.txt +++ b/doc/Comment.txt @@ -158,6 +158,10 @@ Mappings *comment.config.Mappings* `gc{motion}` and `gb{motion}` (default: 'true') {extra} (boolean) Enable extra mapping; `gco`, `gcO` and `gcA` (default: 'true') + {line} (boolean) Enables operator-pending mapping; `gcc` + `gc{motion}` (default: 'true') + {block} (boolean) Enables operator-pending mapping; `gbc` + `gb{motion}` (default: 'true') Toggler *comment.config.Toggler* diff --git a/lua/Comment/config.lua b/lua/Comment/config.lua index 01be20f0..b2bc8cba 100644 --- a/lua/Comment/config.lua +++ b/lua/Comment/config.lua @@ -57,6 +57,12 @@ ---Enable extra mapping; `gco`, `gcO` and `gcA` ---(default: 'true') ---@field extra boolean +---Enable line mapping; `gcc` +---(default: 'true') +---@field line boolean +---Enable block mapping; `gbc` +---(default: 'true') +---@field block boolean ---LHS of toggle mappings in NORMAL ---@class Toggler @@ -86,6 +92,8 @@ local Config = { mappings = { basic = true, extra = true, + line = true, + block = true }, toggler = { line = 'gcc', diff --git a/lua/Comment/init.lua b/lua/Comment/init.lua index 2cdfc7b8..edcc1aae 100644 --- a/lua/Comment/init.lua +++ b/lua/Comment/init.lua @@ -97,31 +97,45 @@ function C.setup(config) -- Basic Mappings if cfg.mappings.basic then -- NORMAL mode mappings - K('n', cfg.opleader.line, '(comment_toggle_linewise)', { desc = 'Comment toggle linewise' }) - K('n', cfg.opleader.block, '(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' }) - K('n', cfg.toggler.line, function() - return vvar('count') == 0 and '(comment_toggle_linewise_current)' - or '(comment_toggle_linewise_count)' - end, { expr = true, desc = 'Comment toggle current line' }) - K('n', cfg.toggler.block, function() - return vvar('count') == 0 and '(comment_toggle_blockwise_current)' - or '(comment_toggle_blockwise_count)' - end, { expr = true, desc = 'Comment toggle current block' }) + if cfg.mappings.line then + K('n', cfg.opleader.line, '(comment_toggle_linewise)', { desc = 'Comment toggle linewise' }) + end + if cfg.mappings.block then + K('n', cfg.opleader.block, '(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' }) + end + + if cfg.mappings.line then + K('n', cfg.toggler.line, function() + return vvar('count') == 0 and '(comment_toggle_linewise_current)' + or '(comment_toggle_linewise_count)' + end, { expr = true, desc = 'Comment toggle current line' }) + end + + if cfg.mappings.block then + K('n', cfg.toggler.block, function() + return vvar('count') == 0 and '(comment_toggle_blockwise_current)' + or '(comment_toggle_blockwise_count)' + end, { expr = true, desc = 'Comment toggle current block' }) + end -- VISUAL mode mappings - K( - 'x', - cfg.opleader.line, - '(comment_toggle_linewise_visual)', - { desc = 'Comment toggle linewise (visual)' } - ) - K( - 'x', - cfg.opleader.block, - '(comment_toggle_blockwise_visual)', - { desc = 'Comment toggle blockwise (visual)' } - ) + if cfg.mappings.line then + K( + 'x', + cfg.opleader.line, + '(comment_toggle_linewise_visual)', + { desc = 'Comment toggle linewise (visual)' } + ) + end + if cfg.mappings.block then + K( + 'x', + cfg.opleader.block, + '(comment_toggle_blockwise_visual)', + { desc = 'Comment toggle blockwise (visual)' } + ) + end end -- Extra Mappings