I want to write a function that closes open HTML tags, because closetag.vim seems complicated, and I like to understand all the stuff I run in Vim.
My plan for this is to match the most recent previous
<\w+ segment, grab whatever is
\w+, and then output
</\1> at the cursor location when I ran this function.
How do I set a variable in my function equal to the most recent previous instance of
\w\+ that comes after a
<? I can do the search with
?<\(\w\+\), but nothing I've found will honor the capture group usage.
I have found
getline on SO), but it certainly feels like there should be an easier way than using two builtins together. I know about the search register, but that only contains the literal regex above, not what it has matched to.
It looks like a similar question was asked 5 months ago but the only answer is about matching tags on the same line, and I would like to do more. I found this question that says how to visually highlight the whole match, but can't handle capture groups, though it looks like the best method if I give up on the capture group limitation.
TL;DR: Is there a simple way to get the contents of a capture group search result into a variable?