Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 4 additions & 0 deletions doc/Comment.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
8 changes: 8 additions & 0 deletions lua/Comment/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -86,6 +92,8 @@ local Config = {
mappings = {
basic = true,
extra = true,
line = true,
block = true
},
toggler = {
line = 'gcc',
Expand Down
58 changes: 36 additions & 22 deletions lua/Comment/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,31 +97,45 @@ function C.setup(config)
-- Basic Mappings
if cfg.mappings.basic then
-- NORMAL mode mappings
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)', { desc = 'Comment toggle linewise' })
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })

K('n', cfg.toggler.line, function()
return vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(comment_toggle_linewise_count)'
end, { expr = true, desc = 'Comment toggle current line' })
K('n', cfg.toggler.block, function()
return vvar('count') == 0 and '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)'
end, { expr = true, desc = 'Comment toggle current block' })
if cfg.mappings.line then
K('n', cfg.opleader.line, '<Plug>(comment_toggle_linewise)', { desc = 'Comment toggle linewise' })
end
if cfg.mappings.block then
K('n', cfg.opleader.block, '<Plug>(comment_toggle_blockwise)', { desc = 'Comment toggle blockwise' })
end

if cfg.mappings.line then
K('n', cfg.toggler.line, function()
return vvar('count') == 0 and '<Plug>(comment_toggle_linewise_current)'
or '<Plug>(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 '<Plug>(comment_toggle_blockwise_current)'
or '<Plug>(comment_toggle_blockwise_count)'
end, { expr = true, desc = 'Comment toggle current block' })
end

-- VISUAL mode mappings
K(
'x',
cfg.opleader.line,
'<Plug>(comment_toggle_linewise_visual)',
{ desc = 'Comment toggle linewise (visual)' }
)
K(
'x',
cfg.opleader.block,
'<Plug>(comment_toggle_blockwise_visual)',
{ desc = 'Comment toggle blockwise (visual)' }
)
if cfg.mappings.line then
K(
'x',
cfg.opleader.line,
'<Plug>(comment_toggle_linewise_visual)',
{ desc = 'Comment toggle linewise (visual)' }
)
end
if cfg.mappings.block then
K(
'x',
cfg.opleader.block,
'<Plug>(comment_toggle_blockwise_visual)',
{ desc = 'Comment toggle blockwise (visual)' }
)
end
end

-- Extra Mappings
Expand Down