I've the following sample content which I want to edit:
<table>
<tr><td title="Title 1">col1</td><td>col2</td><td>col3</td></tr>
<tr><td title="Title 2">col1</td><td>col2</td><td>col3</td></tr>
<tr><td title="Title 3">col1</td><td>col2</td><td>col3</td></tr>
</table>
Note: It doesn't matter it's HTML, that kind of operation can apply to any format, so I'm not interested in HTML parsers.
Where I'd like to copy all values of title
into separate column, so the expected result is:
<table>
<tr><td title="Title 1">col1</td><td>col2</td><td>col3</td><td>Title 1</td></tr>
<tr><td title="Title 2">col1</td><td>col2</td><td>col3</td><td>Title 2</td></tr>
<tr><td title="Title 3">col1</td><td>col2</td><td>col3</td><td>Title 3</td></tr>
</table>
My plan is to find all td title
using global command (g
) and execute normal commands:
- Copy quoted text (
f"lyt"
). - Find
</td></tr>
(/<.td><.tr>
,<CR>
?). - Append
<div>
(a<div>
,<Esc>
?) - Paste yanked text (
p
). - Append
</div>
(a</div>
,<Esc>
?)
But I don't know how to simulate presses of Enter and Escape after search or text appending.
I've tried this:
:g/td title/norm f"lyt"/<.td><.tr><CR>f>a<td><Esc>pa</td><Esc>
but it doesn't work, because <CR>
and <Esc>
aren't recognised as keystrokes.
Although it works when I insert these keystrokes manually while typing the command by using Control-V, then Control+Enter (^M
) or Control+Escape (^[
).
Is there any alternative method where I can insert those keystrokes without using Control-V?