Homem Robô
Homem Robô

Reputation: 3

vim mapping keys to surround words/lines with <p></p>

I'm trying to map the keys ALT+SHIFT+W to surround the text/line with <p></p> tags.

Right now I have this on my _vimrc file:

map <A-S-w> c<p><C-R>"<p><ESC>

But this produces:

<p>Some text.<p></p></p>

What I'm doing wrong? I have to scape the first "<p>" on my map?

Thanks

Upvotes: 0

Views: 607

Answers (2)

Prince Goulash
Prince Goulash

Reputation: 15715

This has already been answered, but may I suggest a version that doesn't overwrite the default register:

vnoremap <A-S-w> <ESC>`>a<\p><ESC>`<i<p><ESC>

It makes use of the < and > markers to go to the most recent visual selection. Note that vnoremap is safer than a basic map because (a) it is restricted to visual mode, and (b) it is non-recursive.

Upvotes: 2

dave
dave

Reputation: 2269

You wrote wrong mapping. The correct is:

map <A-S-w> c<p><C-R>"</p><ESC>

Upvotes: 2

Related Questions