Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ultsnips transformation not working as desired #1555

Open
kontrapunktstefan opened this issue Jul 6, 2024 · 1 comment
Open

Ultsnips transformation not working as desired #1555

kontrapunktstefan opened this issue Jul 6, 2024 · 1 comment
Labels
answered or workaround exists pending feedback sample snippet Resolution contains a sample snippet that solves OP's use case triaged Bugs that I had a look at user question

Comments

@kontrapunktstefan
Copy link

I have written the following snippet for UltiSnips in Vim. With this snippet I want to add an apostrophe to all lilypond pitches:

snippet 1 "lilypond pitches with apostophes"
$1
${1/\w+\s*/$0'/g}
endsnippet

When I execute it, however, the text appears twice:

c d e
c' d' e'

I just want the 2nd line

I've tried snippet 1 "lilypond pitches with apostophes"

snippet 1
${1/\w+\s*/$0'/g}
endsnippet

but this gives an error:

UltiSnips Error:

Tabstop 1 is not known but is used by a Transformation
@SirVer
Copy link
Owner

SirVer commented Jul 14, 2024

Hey, you cannot change what you typed yourself, that is a limitation of Vim, unfortunately. The best you can do is something like this:

snippet apo "lilypond pitches with apostophes"
`!p
lines = []
for idx, line in enumerate(snip.v.text.splitlines()):
	lines.append(" ".join(f"{a}'" for a in line.split()))
snip.rv = "\n".join(lines)
`
endsnippet

You use it like this:

  1. type out your line c d e
  2. Visual select the line (i.e. in normal mode, V)
  3. expand (not sure what your trigger is, maybe <tab>), this will remove the text
  4. type apo<tab> or whatever your expand trigger is
  5. output line is c' d' e'.

Hope that helps

@SirVer SirVer added triaged Bugs that I had a look at user question pending feedback answered or workaround exists sample snippet Resolution contains a sample snippet that solves OP's use case labels Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered or workaround exists pending feedback sample snippet Resolution contains a sample snippet that solves OP's use case triaged Bugs that I had a look at user question
2 participants