-
-
Notifications
You must be signed in to change notification settings - Fork 948
Expand file tree
/
Copy pathcomment.lua
More file actions
53 lines (53 loc) · 2.25 KB
/
comment.lua
File metadata and controls
53 lines (53 loc) · 2.25 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
-- TODO: Remove when dropping support for Neovim v0.10
return {
"numToStr/Comment.nvim",
enabled = vim.fn.has "nvim-0.11" ~= 1,
specs = {
{
"AstroNvim/astrocore",
opts = function(_, opts)
local maps = opts.mappings
maps.n["<Leader>/"] = {
function()
return require("Comment.api").call(
"toggle.linewise." .. (vim.v.count == 0 and "current" or "count_repeat"),
"g@$"
)()
end,
expr = true,
silent = true,
desc = "Toggle comment line",
}
maps.x["<Leader>/"] = {
"<Esc><Cmd>lua require('Comment.api').locked('toggle.linewise')(vim.fn.visualmode())<CR>",
desc = "Toggle comment",
}
end,
},
},
keys = function(_, keys)
local plugin = require("lazy.core.config").spec.plugins["Comment.nvim"]
local opts = require("lazy.core.plugin").values(plugin, "opts", false)
if vim.tbl_get(opts, "mappings", "basic") ~= false then
vim.list_extend(keys, {
{ vim.tbl_get(opts, "toggler", "line") or "gcc", desc = "Comment toggle current line" },
{ vim.tbl_get(opts, "toggler", "block") or "gbc", desc = "Comment toggle current block" },
{ vim.tbl_get(opts, "opleader", "line") or "gc", desc = "Comment toggle linewise" },
{ vim.tbl_get(opts, "opleader", "block") or "gb", desc = "Comment toggle blockwise" },
{ vim.tbl_get(opts, "opleader", "line") or "gc", mode = "x", desc = "Comment toggle linewise (visual)" },
{ vim.tbl_get(opts, "opleader", "block") or "gb", mode = "x", desc = "Comment toggle blockwise (visual)" },
})
end
if vim.tbl_get(opts, "mappings", "extra") ~= false then
vim.list_extend(keys, {
{ vim.tbl_get(keys, "extra", "below") or "gco", desc = "Comment insert below" },
{ vim.tbl_get(opts, "extra", "above") or "gcO", desc = "Comment insert above" },
{ vim.tbl_get(opts, "extra", "eol") or "gcA", desc = "Comment insert end of line" },
})
end
end,
opts = function(_, opts)
local commentstring_avail, commentstring = pcall(require, "ts_context_commentstring.integrations.comment_nvim")
if commentstring_avail then opts.pre_hook = commentstring.create_pre_hook() end
end,
}