diff options
author | Abouzar Parvan <[email protected]> | 2021-10-11 20:10:59 +0330 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-11 20:10:59 +0330 |
commit | 3dc24cd0c32801afd44c0451932f8245cdf10a49 (patch) | |
tree | 1d21aa504885607703827eedabc6c6c71aba7a8c /lua | |
parent | 965ea4bbb902d2f58108c5c01fcb6442e6aff51b (diff) |
[Feature] use `Comment.nvim` instead of `nvim-comment` (#1736)
Diffstat (limited to 'lua')
-rw-r--r-- | lua/lvim/core/comment.lua | 66 | ||||
-rw-r--r-- | lua/lvim/core/which-key.lua | 4 | ||||
-rw-r--r-- | lua/lvim/plugins.lua | 2 |
3 files changed, 56 insertions, 16 deletions
diff --git a/lua/lvim/core/comment.lua b/lua/lvim/core/comment.lua index b98410ab..0b454074 100644 --- a/lua/lvim/core/comment.lua +++ b/lua/lvim/core/comment.lua @@ -1,26 +1,66 @@ local M = {} function M.config() + local pre_hook = nil + if lvim.builtin.treesitter.context_commentstring.enable then + pre_hook = function(_ctx) + return require("ts_context_commentstring.internal").calculate_commentstring() + end + end lvim.builtin.comment = { active = true, on_config_done = nil, - -- Linters prefer comment and line to have a space in between markers - marker_padding = true, - -- should comment out empty or whitespace only lines - comment_empty = false, - -- Should key mappings be created - create_mappings = true, - -- Normal mode mapping left hand side - line_mapping = "gcc", - -- Visual/Operator mapping left hand side - operator_mapping = "gc", - -- Hook function to call before commenting takes place - hook = nil, + ---Add a space b/w comment and the line + ---@type boolean + padding = true, + + ---Lines to be ignored while comment/uncomment. + ---Could be a regex string or a function that returns a regex string. + ---Example: Use '^$' to ignore empty lines + ---@type string|function + ignore = "^$", + + ---Whether to create basic (operator-pending) and extra mappings for NORMAL/VISUAL mode + ---@type table + mappings = { + ---operator-pending mapping + ---Includes `gcc`, `gcb`, `gc[count]{motion}` and `gb[count]{motion}` + basic = true, + ---extended mapping + ---Includes `g>`, `g<`, `g>[count]{motion}` and `g<[count]{motion}` + extra = false, + }, + + ---LHS of line and block comment toggle mapping in NORMAL/VISUAL mode + ---@type table + toggler = { + ---line-comment toggle + line = "gcc", + ---block-comment toggle + block = "gbc", + }, + + ---LHS of line and block comment operator-mode mapping in NORMAL/VISUAL mode + ---@type table + opleader = { + ---line-comment opfunc mapping + line = "gc", + ---block-comment opfunc mapping + block = "gb", + }, + + ---Pre-hook, called before commenting the line + ---@type function|nil + pre_hook = pre_hook, + + ---Post-hook, called after commenting is done + ---@type function|nil + post_hook = nil, } end function M.setup() - local nvim_comment = require "nvim_comment" + local nvim_comment = require "Comment" nvim_comment.setup(lvim.builtin.comment) if lvim.builtin.comment.on_config_done then diff --git a/lua/lvim/core/which-key.lua b/lua/lvim/core/which-key.lua index eebdc27b..528c7600 100644 --- a/lua/lvim/core/which-key.lua +++ b/lua/lvim/core/which-key.lua @@ -61,12 +61,12 @@ M.config = function() -- NOTE: Prefer using : over <cmd> as the latter avoids going back in normal-mode. -- see https://neovim.io/doc/user/map.html#:map-cmd vmappings = { - ["/"] = { ":CommentToggle<CR>", "Comment" }, + ["/"] = { "<ESC><CMD>lua ___comment_gc(vim.fn.visualmode())<CR>", "Comment" }, }, mappings = { ["w"] = { "<cmd>w!<CR>", "Save" }, ["q"] = { "<cmd>q!<CR>", "Quit" }, - ["/"] = { "<cmd>CommentToggle<CR>", "Comment" }, + ["/"] = { "<cmd>lua require('Comment').toggle()<CR>", "Comment" }, ["c"] = { "<cmd>BufferClose!<CR>", "Close Buffer" }, ["f"] = { "<cmd>Telescope find_files<CR>", "Find File" }, ["h"] = { "<cmd>nohlsearch<CR>", "No Highlight" }, diff --git a/lua/lvim/plugins.lua b/lua/lvim/plugins.lua index 44fc4dd3..84522366 100644 --- a/lua/lvim/plugins.lua +++ b/lua/lvim/plugins.lua @@ -102,7 +102,7 @@ return { -- Comments { - "terrortylor/nvim-comment", + "numToStr/Comment.nvim", event = "BufRead", config = function() require("lvim.core.comment").setup() |