SirVer / ultisnips

UltiSnips - The ultimate snippet solution for Vim. Send pull requests to SirVer/ultisnips!
GNU General Public License v3.0
7.55k stars 691 forks source link

Ultsnips transformation not working as desired #1555

Closed kontrapunktstefan closed 2 months ago

kontrapunktstefan commented 4 months ago

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 commented 4 months ago

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

kontrapunktstefan commented 2 months ago

Dear Holger, thanks for Your reply. I've found a solution with a vim script.

Am Di., 10. Sept. 2024 um 14:18 Uhr schrieb Holger Rapp < @.***>:

Closed #1555 https://github.com/SirVer/ultisnips/issues/1555 as completed.

— Reply to this email directly, view it on GitHub https://github.com/SirVer/ultisnips/issues/1555#event-14197900012, or unsubscribe https://github.com/notifications/unsubscribe-auth/AROZ3ITFGCK36MYEAYIDR3LZV3PRVAVCNFSM6AAAAABKOIJMMKVHI2DSMVQWIX3LMV45UABCJFZXG5LFIV3GK3TUJZXXI2LGNFRWC5DJN5XDWMJUGE4TOOJQGAYDCMQ . You are receiving this because you authored the thread.Message ID: @.***>