Closed ertwro closed 1 year ago
Hi! Please clarify a few things to make sure we understand each other:
Ok. Yes, I'm using Neovim 0.8 I used to have Vim and used UltiSnips. Now I'm full time on Neovim. I'm trying to switch to Luasnip since is what Neovim uses. The format I would like is the native Luasnip. So far I've tried a couple things like a converter that outputs in the JSON format (which works fine for most simple snippets) or writing new entries myself in Lua based on the examples you provided in your guide. Where am stuck is in translating complex snippets that use python code to Lua. E.g.
priority 1000
context "math()"
snippet '^.*\)/' "() frac" wrA
`!p
stripped = match.string[:-1]
depth = 0
i = len(stripped) - 1
while True:
if stripped[i] == ')': depth += 1
if stripped[i] == '(': depth -= 1
if depth == 0: break;
i-=1
snip.rv = stripped[0:i] + "\\frac{" + stripped[i+1:-1] + "}"
`{$1}$0
endsnippet
And I've tried turning it into something like this, which is most likely complete nonesense.
s(
{ trig = "([^.*])%/", dscr="() frac", wordTrig = false, regTrig = true, snippetType = "autosnippet" },
fmta(
f(function(_, snip)
!p local stripped = snip.captures[1,-2)]
local depth = 0 local i = #stripped
while true do
if stripped:sub(i,i) == ')'
then
depth = depth + 1
end
if stripped:sub(i,i) == '('
then depth = depth - 1 end
if depth == 0
then break
end;
i=i-1
end
end),
d(1, get_visual),
i(1, 'snip.rv = stripped:sub(1,i) .. "\\frac{" .. stripped:sub(i+2,-2) .. "}" {$1}$0)',
}),
{ condition = tex.in_mathzone }
}
Okay I understand now, thanks for taking the time to clarify things! Two comments:
I wish I could be more helpful, but I'd suggest either using UltiSnips with Neovim (if you want to keep using Castel's snippets) or, if you are want to use Luasnip, to write snippets by hand in Lua (probably start with something simpler than Castel's).
Thank You very Much. Your're right I need to start simple I've been following Tj DevRies series and others to learn. Fortunately I found someone who translated the hardest of the functions in Castel's snippets. I'm sharing it with you so maybe you can find them useful too. "iurimateus/luasnip-latex-snippets.nvim"
I was very sad to know of Mr. Castel's passing. He was so Young. Is a great loss.
Thanks for the updates and sorry for the late reply! Closing this issue, as it seems we have reached a resolution.
Hi. First of all thanks for your guide on using snippets with neovim. I’m not a programmer am a physician and I’m slowly migrating my snippets to lua but the reason I started was to do what Mr. Castell was doing when writing math. Is there a way to use his ultisnips with neovim? Migrating the more than 100 math snippets will take a while and time is not something I have a lot of. Thanks for everything.