Skip to content

Instantly share code, notes, and snippets.

@sunjon
Created November 19, 2021 03:07
Show Gist options
  • Save sunjon/2414a671ade378766eff503ac505294c to your computer and use it in GitHub Desktop.
Save sunjon/2414a671ade378766eff503ac505294c to your computer and use it in GitHub Desktop.
local U = require "Comment.utils"
local VISUAL_LINE = U.cmotion["V"]
local min, max = math.min, math.max
require("Comment").setup {
opleader = {
-- line = "gc", -- TODO: had to switch these to achieve the lua behaviour wanted
line = "gb",
-- block = "gb",
block = "gc",
},
pre_hook = function(ctx)
-- determine whether to use linewise or blockwise commentstrng (only for linewise visual selections)
if vim.bo.filetype == "lua" and (ctx.cmotion == VISUAL_LINE) then
local region = U.get_region "V"
local diff = max(region.srow, region.erow) - min(region.srow, region.erow)
ctx.ctype = (diff > 0) and U.ctype.block or U.ctype.line
end
end,
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment