1

Let's say I have the following snippet:

snippet divt
    <div id="${1:div_id}">
        ${2:'some text'}
    </div>

So when I type divt and hit tab twice "'some text'" should be selected, and when I hit tab once more I would like "some text" to be selected (witoutht single quotes). How can I do it?

Edit 1: Thanks for your answers. Probably this example makes more sense:

snippet divt
    <div ${1:id="${2:div_id}"}>
    </div>

Sometimes I want a div without an id, so i need to be able to delete the id="div_id" altogether. Sometimes i'd like to have an id, so that i can change div_id part only.

2 Answers2

1

SnipMate unfortunately doesn't support nested placeholders but, as per @Benoit's advice, you could use another snippet while editing the second placeholder. Be sure to bring a spinning top with you, though.

I'm not sure what you want to achieve with some text vs 'some text' — both being treated exactly the same way in this context by every html parser on earth — but I would achieve that with a simple

snippet div
    <div id="${1:div_id}">
        ${2}
    </div>

and simply typing either

some text

or

'

which would be expanded to (| is the caret)

'|'

thanks to delimitMate or any other similar plugin then

'some text'

Or maybe use surround to change

some text|

into

'some text'

by typing

<Esc>v2bS'

With Surround you can also start with

some text

select it with

v2e

or something similar and type

S'

to add the quotes then select the line with

V

and type

S<div id="div_id">

to obtain

<div id="div_id">
    'some text'
</div>

or do it the other way or... someone has to write a blog post with ALL the possible ways to achieve a given task in Vim.

romainl
  • 186,200
  • 21
  • 280
  • 313
1

I am currently on a promoting trip for UltiSnips which I am maintaning. The snippet that does precisely that looks like this for UltiSnips:

snippet divt "div" b
<div ${1:id="${2:div_id}"}>
</div>
endsnippet

UltiSnips also comes with a converter script for snipMate snippets, so switching should be painless.

SirVer
  • 1,397
  • 1
  • 16
  • 15
  • Thanks for the reply. I have found out about UltiSnips recently. It's great. –  Jul 27 '11 at 06:09