-
-
Notifications
You must be signed in to change notification settings - Fork 246
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
[Feature] Is it possible to match text after cursor? #851
Comments
Whew, that's pretty specific, but also a cool idea :D You could make use of Not trivial, unfortunately :/ |
Thanks for your suggestion, actually I have come up with an ugly but working solution during the time: s({ trig = '$$', snippetType = 'autosnippet' } , {
d(1, function()
local line = api.nvim_get_current_line()
local col = api.nvim_win_get_cursor(0)[2]
if line:sub(col, col) == '$' then
api.nvim_set_current_line(line:sub(1, col-1) .. line:sub(col+1))
return sn(nil, { t { '$$', '' }, i(1), t { '', '$$' } })
else
return sn(nil, { t '$', i(1), t '$' })
end
end),
}) I also want to report a bug here that if I set the jump index of the snippet above to
the snippet that triggers the bug is (just change the jump index from s({ trig = '$$', snippetType = 'autosnippet' } , {
d(0, function()
local line = api.nvim_get_current_line()
local col = api.nvim_win_get_cursor(0)[2]
if line:sub(col, col) == '$' then
api.nvim_set_current_line(line:sub(1, col-1) .. line:sub(col+1))
return sn(nil, { t { '$$', '' }, i(0), t { '', '$$' } })
else
return sn(nil, { t '$', i(0), t '$' })
end
end),
}) Can you reproduce it? EDIT: remove unrelated lines. |
For this specific case is not better to use a choice node alternating between an input and an input surrounded by two texts (with the |
@leiserfg That is a good idea too, thanks for your suggestion. |
Something like this should work: s({ trig = "$$", snippetType = "autosnippet" }, {
t "$",
c(1, {
i(1),
sn(1, {
t { "$", "" },
i(1),
t { "", "$" },
}),
}),
t "$",
}), |
@leiserfg Thanks for the snippet, but I think I prefer the way that does not use a choice node. If I use a choice node, for inserting a display math, I have press The problem here is that I cannot set the jump index of the dynamic node and the insert node inside it to |
Talk about not seeing the forest for the trees xD |
Ah yeah the 0-jump-index can only be occupied by an insertNode, you'll have to live with that limitation, unfortunately :/ |
@L3MON4D3 Oh I forget that only insert nodes can have jump index For future readers that come across this issue, an ugly (but working) solution is: s({
trig = '$',
condition = function()
local line = api.nvim_get_current_line()
local col = api.nvim_win_get_cursor(0)[2]
return line:sub(col + 1, col + 1) == '$'
end,
}, { t({ '$', '' }), ifn(1), i(0), t({ '', '$' }) })
s(
{ trig = '$$', priority = 999 },
{ t('$'), i(0), t('$') }
) the snippet above will not put a final jump destination after expanding the snippet, which is exactly what I want. |
First thanks for making this plugin, it works really fast and smooth and boosts
my speed in neovim, especially for latex files.
I want to make a snippet for quickly creating math environments. In latex there
there are inline maths and display maths:
Snippet for inline math is relatively simple:
In the snippet above, I can put my cursor in the middle of the dollars after
inserting two consecutive dollar signs.
However, for display math, things get tricky, what I want to achieve is:
I first type two consecutive dollar signs, the snippet for inline math is
triggered:
Then I press
$
again in between the two dollars, the snippet for displaymath is triggered:
This requires the snippet to be able to detect texts after the cursor
and remove some of them after the snippet is expanded if needed.
I looked at the documentation carefully, but I didn't find a way to do this.
Is it possible to do this with the current version of the plugin?
Thanks in advance! :)
The text was updated successfully, but these errors were encountered: