0

I use vim for programming purposes and I use the snipMate utility. I'm aware of the basic snippets definition, but I'm trying to do something like the following (this doesn't work):

snippet ${1}_.
    <$1 class="${2}">${3}</$1>

I think it would be easier to explain with an example. What I'm trying to do is to insert a html tag when typing a word followed by _. :

So if I type div_. and press tab, it should change to:

<div class="(position of cursor)">(position of cursor)</div>

If I type span_. and press tab, it should change to:

<span class="(position of cursor)">(position of cursor)</span>

And so on. Hope you get the idea. I'm aware that I can write a snippet for every case, but I'm trying to avoid that.

Thanks!

JLeon
  • 61
  • 5

1 Answers1

1

Make the snippet do the hard work for you:

snippet tag
    <${1:div} class="${2}">${3}</$1>

You may also want to take a look at emmet-vim and surround.vim.

Peter Rincker
  • 43,539
  • 9
  • 74
  • 101
  • Although this is not exactly what I wanted to achieve, it's a pretty good workaround. I'm not gonna accept your answer just yet in case someone comes around with a perfect solution. I took a look at surround.vim and is quite an interesting useful tool! Thanks! – JLeon Feb 25 '15 at 15:27