Multi-line comment textobject #1234
-
Hello, I would like to create a comment textobject that I can use inside mini.ai I know neovim added a comment textobject here but I don't know how to make it work with mini.ai mappings to go to next object, go to previous object, etc. Also, I can't manage to map it to P.S Using treesitter here does not seem to work at it only select a single line of comment, not the whole block. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Unfortunately, it is not an easy thing to do. The reason is because in order to make this work with "next"/"prev" search methods, 'mini.ai' needs to know about them when deciding which one to choose. The built-in commenting was designed to exclusively used interactively, so it doesn't provide any (stable) Lua API. The best approach to solve what you are asking for is to manually write a textobject specification as a function that returns an array of regions representing all consecutive comment blocks. Depending on how robust and capable you want it to be, implementation can span from maybe about 15 lines to at least 50. However, the most reasonable approach to solve the problem I'd say is to utilize [ |
Beta Was this translation helpful? Give feedback.
-
I see. It would also be good to get the select around, select around next, etc. So mini.ai is preferable. I've looked into the codebase and I'm thinking that I could make a function to merge the regions from In mini.ai, is there a way to denote a visual-block selection? For instance everything after column 10 on lines 3, 4, 5? To match these kind of comments as a visual block: a = 5 // comment 1
b = 6 // comment 2
c = 7 // comment 3 |
Beta Was this translation helpful? Give feedback.
Unfortunately, it is not an easy thing to do. The reason is because in order to make this work with "next"/"prev" search methods, 'mini.ai' needs to know about them when deciding which one to choose. The built-in commenting was designed to exclusively used interactively, so it doesn't provide any (stable) Lua API.
The best approach to solve what you are asking for is to manually write a textobject specification as a function that returns an array of regions representing all consecutive comment blocks. Depending on how robust and capable you want it to be, implementation can span from maybe about 15 lines to at least 50.
However, the most reasonable approach to solve the problem I'd say is…