How to comment out a snippet #596
-
I am creating a snippet to quickly create vim modelines, and I'm attempting to comment it out dynamically no matter what language I am expanding it in. I am leveraging the Comment.nvim api in the snippet's callback, but ran into some issues. local snippets = {
s("modeline", fmt([[
vim: set {} :
]], {
i(0, "opt=value opt=value")
}), {
callbacks = {
[0] = {
[events.enter] = function()
require("Comment.api").toggle.linewise.current()
end
}
},
}),
} With this implementation, the only issue is that the text that is selected for the insert node is in its original position before the comment characters were inserted: Any tips on how to fix this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 14 replies
-
Hmmm, the problem is that we select the text before firing the event... One solution to this issue is of course to fire the event before selecting (eg. executing the "enter"), but I'm not sure we disable some other workflow with that. Until then, I think you could get away with re-using the code we use to select the insertNode (select again after toggling the comment) though I won't promise that this'll work indefinitely :P |
Beta Was this translation helpful? Give feedback.
-
You can use the |
Beta Was this translation helpful? Give feedback.
You can use the
LINE_COMMENT
or theBLOCK_COMMENT_START
BLOCK_COMMENT_END
environment variables.