kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

Luasnip configuration (not a bug)

Open prscoelho opened this issue 2 years ago • 1 comments

Hello! There was some weird behavior that took me awhile and a lot of frustration to figure out, where I was editing somewhere and pressing tab caused the cursor to completely jump to somewhere else!

It turned out that this is actually intended, and it happens if you don't complete the luasnip, it jumps back to the first non completed luasnip item. How do you feel about configuring this behavior in this repository?

Prior discussion in luasnip:

  • https://github.com/L3MON4D3/LuaSnip/issues/258
  • https://github.com/L3MON4D3/LuaSnip/issues/656

Behavior in vsc*de seems to be that once you move to a new line the snippet is forgotten.

There's a few solutions in the issues linked above, I went with the following which seemed to work well enough.

local unlinkgrp = vim.api.nvim_create_augroup(
  'UnlinkSnippetOnModeChange',
  { clear = true }
)

vim.api.nvim_create_autocmd('ModeChanged', {
  group = unlinkgrp,
  pattern = {'s:n', 'i:*'},
  desc = 'Forget the current snippet when leaving the insert mode',
  callback = function(evt)
    if
      luasnip.session
      and luasnip.session.current_nodes[evt.buf]
      and not luasnip.session.jump_active
    then
      luasnip.unlink_current()
    end
  end,
})

prscoelho avatar Dec 31 '22 03:12 prscoelho

Alternatively, this also works and is probably better?

luasnip.config.set_config({
  ['region_check_events'] = 'InsertEnter',
})

prscoelho avatar Dec 31 '22 19:12 prscoelho