0

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

2 Answers2

2

You wrote wrong mapping. The correct is:

map <A-S-w> c<p><C-R>"</p><ESC>
dave
  • 2,199
  • 1
  • 16
  • 34
  • thanks! I feel dumb.. but I have a plugin that auto-closes that p, so this is the main problem there.. now I got this working. – Homem Robô Jul 11 '11 at 15:31
  • 4
    @Homem Robo, @black You all should use `nore` (`noremap`). If you did, this problem would not appear because that plugin mapping have not been invoked. It is a general rule while writing *any* mapping: use `nore` unless {rhs} contains only *known* *remapped* key sequences (like `Something`). *Known* and *remapped* or you may run into trouble. – ZyX Jul 11 '11 at 17:01
  • Done! `noremap c

    "

    `
    – Homem Robô Jul 13 '11 at 17:08
2

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.

Prince Goulash
  • 15,295
  • 2
  • 46
  • 47
  • I'm new on vim, so I still don't get the visual mode on my workflow right now. I have to learn more of vim. But thanks for the tip. – Homem Robô Jul 11 '11 at 15:34
  • 1
    A visual selection is anything selected by pressing `v`, `V` or ``, so I assumed that's what you were doing. It's a good habit to use `noremap` unless there's a good reason not to. – Prince Goulash Jul 11 '11 at 15:37
  • Actually I'm having trouble with vim modes right now. I have this on my vimrc: behave mswin. This is not good right? – Homem Robô Jul 11 '11 at 16:09
  • There's nothing wrong with `behave mswin` (although I don't use it). One of its side-effects to remap `` to paste, so block-wise visual mode is remapped to ``. – Prince Goulash Jul 12 '11 at 09:59