summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/plugins/comment.lua
blob: 6e9a55ebf9f462c7ba237b4983ca300d7756de21 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
return {
    'numToStr/Comment.nvim',
    opts = {
        padding = true,
        ignore = nil,

        toggler = { line = 'gcc', block = 'gbc' },
        opleader = { line = 'gc', block = 'gb' },
        extra = { above = 'gcO', below = 'gco', eol = 'gcA' },

        mappings = {
            basic = true, -- `gcc` `gbc` `gc[count]{motion}` `gb[count]{motion}`
            extra = false, -- `gco`, `gcO`, `gcA`
        },
    },
    config = function()
        local api = require('Comment.api')
        local esc = vim.api.nvim_replace_termcodes('<ESC>', true, false, true)
        -- TODO: Stay in visual mode and keep the same selection even after commenting
        local toggole_linewise_selection = function()
            vim.api.nvim_feedkeys(esc, 'nx', false)
            api.toggle.linewise(vim.fn.visualmode())
        end

        vim.keymap.set('n', '<C-_>', api.toggle.linewise.current, { noremap = true, silent = true })
        vim.keymap.set('v', '<C-_>', toggole_linewise_selection, { noremap = true, silent = true })
    end,
}