I have HTML that looks like this
<form>
<input id="firstname" value=""/>
<input id="lastname" value=""/>
<input id="email" value=""/>
</form>
And I want to add name="{id-name}" to each input field (see example code below)
<form>
<input id="firstname" name="firstname" value=""/>
<input id="lastname" name="lastname" value=""/>
<input id="email" name="email" value=""/>
</form>
How can I do this with Vim?
I am trying
%s/id=".*"/\=submatch(0)/g
And it's resulting in two issues:
1) The search, searches from first quote to last quote. It should be searching from first quote to the next quote.
2.) The submatch(0)
is taking the full result of search. How can I isolate it to only the value between id="{value}"
?
I come across this issue a lot, figuring out this vim command could help save me a lot of time in the future. Mainly splitting search results into the submatch()
I have also seen people on stack use \1 \2
instead of submatch()
to store results, is that approach better?
Any help will be greatly appreciated! Thank you!