diff --git a/dot_config/nvim/exact_lua/exact_plugins/exact_editor/comment.lua b/dot_config/nvim/exact_lua/exact_plugins/exact_editor/comment.lua new file mode 100644 index 0000000..c0330d8 --- /dev/null +++ b/dot_config/nvim/exact_lua/exact_plugins/exact_editor/comment.lua @@ -0,0 +1,64 @@ +-- if true then return {} end -- 暫時停用 +return { + { + "numToStr/Comment.nvim", + opts = { + padding = true, + sticky = true, + ignore = nil, + toggler = { line = 'gcc', block = 'gbc' }, + opleader = { line = 'gc', block = 'gb' }, + extra = { above = 'gcO', below = 'gco', eol = 'gcA' }, + mappings = { basic = true, extra = true }, + pre_hook = nil, + post_hook = nil, + }, + config = function(_, opts) + require("Comment").setup(opts) + + local api = require('Comment.api') + local config = require('Comment.config'):get() + + -- api.toggle.linewise(motion, config?) + -- api.toggle.linewise.current(motion?, config?) + -- api.toggle.linewise.count(count, config?) + + -- api.toggle.blockwise(motion, config?) + -- api.toggle.blockwise.current(motion?, config?) + -- api.toggle.blockwise.count(count, config?) + + -- Toggle current line (linewise) using C-/ + vim.keymap.set('n', '', api.toggle.linewise.current) + + -- -- Toggle current line (blockwise) using C-\ + -- vim.keymap.set('n', '', api.toggle.blockwise.current) + + -- Toggle lines (linewise) with dot-repeat support + -- Example: gc3j will comment 4 lines + vim.keymap.set( + 'n', 'gc', api.call('toggle.linewise', 'g@'), + { expr = true } + ) + + -- Toggle lines (blockwise) with dot-repeat support + -- Example: gb3j will comment 4 lines + vim.keymap.set( + 'n', 'gb', api.call('toggle.blockwise', 'g@'), + { expr = true } + ) + + local esc = vim.api.nvim_replace_termcodes( + '', true, false, true + ) + + -- Toggle selection (linewise) + -- vim.keymap.set('x', 'c', function() + vim.keymap.set('x', '', function() + vim.api.nvim_feedkeys(esc, 'nx', false) + api.toggle.linewise(vim.fn.visualmode()) + end) + + end, + } + +}