I ran into the following vimscript snippet in a book this afternoon and it seems like it'd be really useful. Unfortunately I haven't quite gotten it to work and I'm hoping somebody can tell me what I'm doing wrong.
vmap <silent> ;h :s?^\(\s*\)+'\([^']\+\)',*\s*$?\1\2?g<CR>
When I highlight some markup in visual mode and hit ;h I get the following error:
Pattern not found: ^\(\s*\)+'\([^']\+\)',*\s*$
The vimscript regexp dialect is a little odd and vimscript itself seems a little alien. For all I know there's a typo. Everything after the first '+' is a bit of a mystery. My understanding is that this should convert a selection in visual mode to a quoted version:
<div>
<div class="header">stuff</div>
</div>
to
+ '<div>'
+ ' <div class="header">stuff</div>'
+ '</div>'
In sublime I can do a find/replace with the following expression:
/^(.*)$/+'\1'/
which makes the vimscript version seem a little verbose. Even so I'd like to be able to do it in vim as well.
[Edit: It turns out the above snippet works fine, it just wasn't doing what I thought it was. The text I was looking at listed a pair of these and I was looking at the wrong one. See below:]
vmap <silent> ;h :s?^\(\s*\)+'\([^']\+\)',*\s*$?\1\2?g<CR>
vmap <silent> ;q :s?^\(\s*\)\(.*\)\s*$?\1+'\2'?<CR>