Search code examples
vimcode-snippetssnipmate

help me create a vim snippet (snipmate)


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.


Solution

  • 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.