hsnips
hsnips copied to clipboard
removing parts of the snippet
Hello world, Is it possible to create a snippet whose purpose is to create the similar environment:
snippet aj "Theorem" bA \begin{Teorema}[$1]\label{teo: $1} $2 \end{Teorema} endsnippet
and enable it to do the following: if it is not necessary to write anything in $1, move to $2, but in the meantime have deleted the whole:
[$1]\label{teo: $1}
So when someone doesn't want to write in [$1] of the environment, they don't need to.
I managed to achieve your request (in a quirky way):
snippet aj "Theorem" bA
`` rv = "\\begin{Teorema}" + (t[0].length > 0 ? "[" : "") ``$1`` rv = t[0].length > 0 ? `]\\label{teo: ${t[0]}}` : ""``
$2
\end{Teorema}
endsnippet
However, the cursor is misplaced from one character to the left when I start to input inside the first placeholder.
After a quick investigation, I found out that it is misplaced because of the dynamically inserted prefix [
before the placeholder.
Dynamically inserting more than one character before a placeholder results in more offsets.
On top of that, if you try to use a default value for the content of the first placeholder (${1:default}
instead of $1
) the snippet breaks.
P.S. : you should not use issues to ask for a specific snippet realization, check out discussions (https://github.com/draivin/hsnips/discussions) for this purpose.
Thank you for the answer,
I have tried your solution but it doesn't work properly;
if you type "aj" (then the snippet expands) and then you type for example "gauss", the snippet doesn't work
I just checked it out once again and on my computer writing "gauss" results in the following:
\begin{Teorema}[aussg]\label{teo: aussg}
\end{Teorema}
(the g is at the end for the reason evoked in my first comment)
Disclaimer: It might work on my vscode and not yours because I have the vim extension installed, I know having both vim and hsnips creates some weird conflicts...