Removing contents of a tabstop

Asked by Dag Odenhall

OK, so, given a snippet like this:

snippet data "Algebraic data type" !b
data ${1:Type} ${2:variables} = ${3:Constructor} | ${0:Constructor}
endsnippet

The second tabstop is optional, but to skip it you have to reach for "delete" and you have to hit it twice to also get rid of the extra space. Is there a better way to handle this sort of thing? I could skip the default and just make it "$2", but then you get less hints at what you're supposed to put there, and you would also need to add the extra space yourself when you do want something in the second tabstop. So, I guess what I want is a way to define whitespace as part of a tabstop, and a mapping to clear the selected text when you jump to a tabstop that's easier to reach than "delete".

(Should I file a feature bug instead?)

Question information

Language:
English Edit question
Status:
Solved
For:
UltiSnips Edit question
Assignee:
No assignee Edit question
Solved by:
SirVer
Solved:
Last query:
Last reply:
Revision history for this message
Best SirVer (sirver) said :
#1

I read two issues in your question.

1) BS is hard to reach: Solution: smap+imap BS to something that you feel more comfortable with (like c-x).
2) Conditionally remove pats of the snippet when a trigger is empty. Solution: Use a conditional regular expression or use python interpolation:

snippet data "Algebraic data type (Python)" b
data ${1:Type} ${2:variables}`!p snip.rv=" " if t[2] else ""`= ${3:Constructor} | ${0:Constructor}
endsnippet

snippet data "Algebraic data type (Cond regexp)" b
data ${1:Type} ${2:variables}${2/.+/(?0: ::)/}= ${3:Constructor} | ${0:Constructor}
endsnippet

I personally find the python version easier to read, but it is slightly more verbose.

Revision history for this message
Dag Odenhall (dag.odenhall) said :
#2

1) I realized that my issue here is that I'm not used to the Select mode, and the selection makes my brain think Vim is in Visual mode. From this realization I discovered that ^Oc will delete the placeholder text without my having to leave the home row. "c" is necessary to end up in Insert mode, otherwise the jump forward/backward triggers of UltiSnips don't work.

2) Works like a charm, thanks!

Revision history for this message
Dag Odenhall (dag.odenhall) said :
#3

Thanks SirVer, that solved my question.

Revision history for this message
SirVer (sirver) said :
#4

>Dag Odenhall confirmed that the question is solved:
>1) I realized that my issue here is that I'm not used to the Select
>mode, and the selection makes my brain think Vim is in Visual mode. From
>this realization I discovered that ^Oc will delete the placeholder text
>without my having to leave the home row. "c" is necessary to end up in
>Insert mode, otherwise the jump forward/backward triggers of UltiSnips
>don't work.
Seems like the solution is to snoremap <C-o> to '<c-g><c-o>' (toggle between select
and visual mode) then.