-
-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature]: adding vim-commentary's gcgc
?
#22
Comments
Is |
Also this might be somewhat related to #11 |
Can we make it |
@astier Nice suggestion. I like the semantics of |
Hello, would you think implementing this is hard? |
Temporary solution based on ---Textobject for adjacent commented lines
local function commented_lines_textobject()
local U = require("Comment.utils")
local cl = vim.api.nvim_win_get_cursor(0)[1] -- current line
local range = { srow = cl, scol = 0, erow = cl, ecol = 0 }
local ctx = {
ctype = U.ctype.linewise,
range = range,
}
local cstr = require("Comment.ft").calculate(ctx) or vim.bo.commentstring
local ll, rr = U.unwrap_cstr(cstr)
local padding = true
local is_commented = U.is_commented(ll, rr, padding)
local line = vim.api.nvim_buf_get_lines(0, cl - 1, cl, false)
if next(line) == nil or not is_commented(line[1]) then
return
end
local rs, re = cl, cl -- range start and end
repeat
rs = rs - 1
line = vim.api.nvim_buf_get_lines(0, rs - 1, rs, false)
until next(line) == nil or not is_commented(line[1])
rs = rs + 1
repeat
re = re + 1
line = vim.api.nvim_buf_get_lines(0, re - 1, re, false)
until next(line) == nil or not is_commented(line[1])
re = re - 1
vim.fn.execute("normal! " .. rs .. "GV" .. re .. "G")
end
vim.keymap.set("o", "gc", commented_lines_textobject,
{ silent = true, desc = "Textobject for adjacent commented lines" })
vim.keymap.set("o", "u", commented_lines_textobject,
{ silent = true, desc = "Textobject for adjacent commented lines" }) |
What if instead of this specific mapping, we just create a general comment text object, and then instead of |
Actually my snippet creates a textobject that can be used not only for commenting but also for other actions: e.g. you can delete a commented block with |
I don't really understand how your snippet works but can't it be just merged so Comment has this feature natively or is there some deal-breaker which makes it not possible? |
I found this useful enough that implemented I implemented such a text object in my plugin, nvim-various-textobjs. to uncomment via keymap("o", "u", "<cmd>lua require('various-textobjs').multiCommentedLines()<CR>") It does not use treesitter and hence does not work with injected languages like codeblocks in markdown, but has no dependency on any comments plugin. |
Neovim v0.10 seems to have a text object for comments vim.keymap.set("n", "gcu", "gcgc", { remap = true }) |
vim-commentary has a normal mode
gcgc
keybinding to uncomment a block of commented lines.Before ↓
After pressing
gcgc
with cursor on line 2 or 3 ↓Also
gbgb
would be really useful to delete block comment without having to select it manuallyThe text was updated successfully, but these errors were encountered: