Closed AllenDang closed 1 year ago
You could use an autocmd
to run require('snippy.buf').clear_state()
, which will clear all jump marks.
@dcampos It's not as easy as I think. I create an autocmd for ModeChange and specify pattern for any mode to normal mode, the snippy jump will be totally disabled for nvim-cmp, reason is, when I hit enter to complete a auto-complete from lsp, the mode will change three times, i->n, n->v, v->s.
How to enable to snippy jump after nvim-cmp's complete and still clean the jump marks when I actually hit esc?
Here is what I did right now.
function leave_snippet()
if (vim.v.event.old_mode == "s" and vim.v.event.new_mode == "n") or vim.v.event.old_mode == "i" then
require("snippy.buf").clear_state()
end
end
-- stop snippets when you leave to normal mode
vim.api.nvim_command([[
autocmd ModeChanged * lua leave_snippet()
]])
I see. Maybe you could set up a mapping for that? This one worked for me:
vim.keymap.set({'i', 's'}, '<Esc>', function()
if require('snippy').is_active() then
require('snippy.buf').clear_state()
end
return '<Esc>'
end, { expr = true })
Problem Statement
Say if current snippet is defined like this
Press ESC to switch to normal mode after jumped to the $4 mark, move the cursor to some place, press "i", press "tab", cursor will still jump to previous snippet's $0 mark.
Ideas or possible solutions
When i press "ESC" to switch to normal mode, all marks of previous snippet should not remain valid.
Alternatives you have considered
Any solution for it? I used to use autocmd to manually disable all jump marks of luasnip when I switched to normal mode.