You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I see no discussion section on ultisnips page, so I post my question here:
how do I access VISUAL (or vim yank register) from post_jump event?
I want snippet for extracting variable e.g. - a+b: something(a + b)
selecting content of bracket and running snipped would generate:
new_var = a+b
something(new_war)
I tried to access snip.v.text or snip.visual_text in post_jump : post_jump "if snip.tabstop == 0: insert_method_call(snip.tabstops[1].current_text, snip.visual_text)"
But ultisnips complains about snip not having v or visual_text props.
My Code
global !p
def post(var_name, visual):
snip.buffer[snip.snippet_start[0]:snip.snippet_start[0]] = [var_name + ' = ' + visual]
endglobal
post_jump "if snip.tabstop == 0: post(snip.tabstops[1].current_text, snip.visual_text)"
snippet var "extract var" b
$1
endsnippet
I also tried to use ${VISUAL} in expand_anon, but no luck.
Finally there is vim - getreg() :
vim.command(":call append(line('.')-1, '"+ var_name + " = '.getreg('+'))")
But then Ultisnip complains about modifying buffer using vim.command.
The text was updated successfully, but these errors were encountered:
In my own snippets, I've extracted this kind of storing the visual text into a global helper, then use it in a snippet that helps me build html tags with attributes, with this line being where the visual text gets extracted from the context.
I see no discussion section on ultisnips page, so I post my question here:
how do I access VISUAL (or vim yank register) from post_jump event?
I want snippet for extracting variable e.g. -
a+b
:something(a + b)
selecting content of bracket and running snipped would generate:
I tried to access snip.v.text or snip.visual_text in post_jump :
post_jump "if snip.tabstop == 0: insert_method_call(snip.tabstops[1].current_text, snip.visual_text)"
But ultisnips complains about snip not having
v
orvisual_text
props.My Code
I also tried to use ${VISUAL} in expand_anon, but no luck.
Finally there is vim - getreg() :
vim.command(":call append(line('.')-1, '"+ var_name + " = '.getreg('+'))")
But then Ultisnip complains about modifying buffer using vim.command.
The text was updated successfully, but these errors were encountered: