-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
chore: refactor utils.get_lines
#73
Conversation
@garymh You might wanna try this :) |
NOTE: The only downside is this duplication will happen every time. But you can determine when to do this by using |
@numToStr Thanks so much!! 😃 |
I suppose this is what you wanted 🙂. |
It works great! I'm a little confused by the |
Ahh, I was also going to suggest making a function for yourself. And yes you can definitely make one for yourself. This plugin is basically a bunch of functions smushed together. So following will work for you local C = require('Comment')
local U = require('Comment.utils')
local Op = require('Comment.opfunc')
local A = vim.api
local opt = { silent = true, noremap = true }
function _G.___gdc(vmode)
local range = U.get_region(vmode)
local cfg = C.get_config()
local ctx = {
cmode = U.cmode.comment, -- Always comment the line
cmotion = U.cmotion.line, -- Line action `gy2j`
ctype = U.ctype.line, -- Use line style comment
range = range,
}
local lcs, rcs = U.parse_cstr(cfg, ctx)
local lines = U.get_lines(range)
-- Copying the block
local srow = ctx.range.erow
A.nvim_buf_set_lines(0, srow, srow, false, lines)
-- Doing the comment
Op.linewise({
cfg = cfg,
cmode = ctx.cmode,
lines = lines,
lcs = lcs,
rcs = rcs,
range = range,
})
-- Move the cursor
local erow = srow + 1
local line = U.get_lines({ srow = srow, erow = erow })
local _, col = U.grab_indent(line[1])
A.nvim_win_set_cursor(0, { erow, col })
end
A.nvim_set_keymap('x', 'gy', '<ESC><CMD>lua ___gdc(vim.fn.visualmode())<CR>', opt)
A.nvim_set_keymap('n', 'gy', '<CMD>set operatorfunc=v:lua.___gdc<CR>g@', opt) |
Works absolutely perfectly! Thanks so much!!! |
Resolves #70
Now you can do this
2021-11-20.13-20-26.mp4