I'd like to create an Ultisnip regex trigger that triggers with multi-line. I'm trying the following:
snippet 'hee\nhaa' "multi-line trigger" r
my awesome result$0
endsnippet
but when in my vim I write :
hee
haa<TAB>
It doesn't work. I tried with \r instead of \n, doesn't work neither. Is it possible to do that ?
tried \r expected a multi-line triggering functionnality
In fact, what I would like to do would be easier done by sed, I know. I have a ledger file (hledger.journal) with many entries. I'd like to update them all ; some are easy done because the syntax is always the same, but other may change because it was more complex entries. The "sed" command on the file would change some entries, other not (and I'm not sure I could use easily my "global python function" I wrote for some calculation on the entries I want to do.
And it would become hard to find entries that need to be update. Doing it with ultisnips is kind of a long way to do so, but I'll have an eye at each update to be sure everything went right.
Almost all lines in the ledger entry contains information that enters in the regex match.group() I have to get in order to update the entry, on with I had some !p snip.rv = calculate(match.group(x), match.group(y) )
etc...
I'm not sure the pre_expand would allow me to get some match.group from the snip.line-1 or snip.line+2 ... and it seems to become heavy...
I really think Ultisnips with a multi-line regex trigger would be the best way to update my ledger file having a "total control" of it being done well, even if it would be an "endless" procedure.
here an actual (simple !) example of an entry of my actual ledger file
2023-07-16 tfuel reward
equity:stak_reward:tfuel:2023-07-16 -12 tfuel
asset:tfuel:Liq:2023-07-16 12 tfuel
there what i would like it to be :
2023-07-16 tfuel reward
income:stak_reward:tfuel:2023-07-16 -0.427 eur
equity:opening_balance:stak_reward:2023-07-16 -0.427 eur
asset:tfuel:Liq:2023-07-16 12 tfuel @ 0.03555137 eur
equity:conv
and here is the snippet i tried to write to do that :
snippet '(\d{4}-\d{2}-\d{2}) tfuel reward\n.*equity.*\n.*tfuel' "migrate all tfuel reward" r
${1:`!p snip.rv = match.group(1)`} tfuel reward
income:stak_reward:tfuel:$1 -${2:`!p snip.rv = calc_value(match.group(1), 'tfuel', 12)`} eur
equity:opening_balance:stak_reward -$2 eur
asset:tfuel:Liq:$1 12 tfuel @ `!p snip.rv = get_token_price_in_eur(match.group(1), 'tfuel')` eur
equity:conv
endsnippet
other more complex entries are with variable asset with variable amount so only one "match.group()" isn't enough, and are on different lines of the trigger
Hope my question is "readable" and make sense... Thank you all !