Chaining Snippets
It is sometimes useful to insert a list where number of items is unknown, but each item has enough boilerplate to want a snippet for it.
One approach to give this a more natural flow is chaining of snippets done e.g. for Rails migrations.
A thread on the mailing list recently resulted in this tip from Brett Terpstra
The idea is that the first snippet inserts the full list and has the last tab stop after the list end marker. So that would be (the class name here is generated from the entry text, specifically it is lowercased and spaces are replaced with underscores):
<ul id="${1:navbar}">
<li class="${2/( )|\w+/(?1:_:\L$0)/g}">
<a href="${3:#}">$2</a>
</li>
</ul>$0
Another snippet inserts a new entry and the list end marker. It has the list end marker itself as tab trigger (i.e. </ul>
), so the snippet is:
<li class="${1/( )|\w+/(?1:_:\L$0)/g}">
<a href="${2:#}">$1</a>
</li>
</ul>$0
This means that when the caret is located after </ul>
you can press tab, and you will extend the list with a new entry, and be able to fill in the text for this new entry.
This means initial creation of the list is just an extra tab for each additional item, and at a later time, it is possible to add new items to the list by placing the caret after the li
end tag and hit tab.