If my cursor is somewhere on an HTML tag, I’d like to invoke a custom command that folds until the closing tag if it finds it, else returns “0” or something.
Should I make a function in VimScript or something?
I imagine it would work something like this:
- Scan left until opening angle bracket is found. If none found, you are not on an HTML tag; return 0.
- Scan right until closing angle bracket tag is found. If second character is backslash, you are on a closing tag; in that case, seek opening tag in next step.
- Search forward (backward) for the matching closing (opening) tag.
- Now fold between the two lines containing those tags.
This also assumes that the HTML tags are spread out on newlines, which for now I am comfortable with.
The main question I have to get started is if I need to track the cursor with an index or if Vim functions are enough to do it. I could search backwards for “<“, enter “v”, search forward with “/“ for “>”, maybe use some copy function to save that string? Or just save it as a variable? There are many such questions that make it hard for me to see the details.
Thanks very much