blink.cmp icon indicating copy to clipboard operation
blink.cmp copied to clipboard

bug(snippets): jump not triggered unless user have entered insert mode before

Open ruslanSorokin opened this issue 3 months ago • 1 comments

Make sure you have done the following

  • [x] Updated to the latest version of blink.cmp
  • [x] Searched for existing issues and documentation (try <C-k> on https://cmp.saghen.dev)

Bug Description

Problem

This happens because we attach keymaps to the buffer on InsertEnter only:

https://github.com/Saghen/blink.cmp/blob/4e9edba1b1cef1585cc65e54287229e5d34e4df8/lua/blink/cmp/keymap/init.lua?plain=1#L77-L85

Repro

Current Behavior

  1. nvim -u repro.lua repro.lua
  2. gg
  3. <space>
  4. <Tab> - doesn't move to the next placeholder

Desired Behavior

  1. nvim -u repro.lua repro.lua
  2. gg
  3. <space>
  4. <Tab> - moves to the next placeholder

Relevant configuration

local function test_func(param1, param2)
	return false
end

-- Run with `nvim -u repro.lua`
--
-- Please update the code below to reproduce your issue and send the updated code, with reproduction
--  steps, in your issue report
--
-- If you get warnings about prebuilt binaries, you may use `fuzzy.implementation = 'lua'`
--  but note this has caveats: https://cmp.saghen.dev/configuration/fuzzy#rust-vs-lua-implementation

vim.env.LAZY_STDPATH = ".repro"
load(vim.fn.system("curl -s https://raw.githubusercontent.com/folke/lazy.nvim/main/bootstrap.lua"))()
vim.bo.tabstop = 2

---@diagnostic disable-next-line: missing-fields
require("lazy.minit").repro({
	spec = {
		{
			"danymat/neogen",
			dependencies = { "nvim-treesitter/nvim-treesitter", "L3MON4D3/LuaSnip" },
        -- stylua: ignore start
				keys = { { "<space>", function() require("neogen").generate() end, desc = "Generate Docs" } },
			-- stylua: ignore end
			opts = { snippet_engine = "luasnip" },
		},
		{
			"saghen/blink.cmp",
			---@module "blink-cmp"
			---@type blink.cmp.Config
			opts = {
				keymap = { preset = "default" },
				snippets = { preset = "luasnip" },
			},
		},
	},
})

neovim version

NVIM v0.11.4 Build type: Release LuaJIT 2.1.1741730670 Run "nvim -V1 -v" for more info

blink.cmp version

main & stable

ruslanSorokin avatar Sep 22 '25 03:09 ruslanSorokin

Thanks for such a detailed report! We shouldn't attach on CursorMoved since we want to apply the keymaps as late as possible. This edge case is tricky, because for built-in snippets, we could listen to ModeChanged where the mode is select or insert. For Luasnip, we don't have such luxury :(

Ideally, we would apply the keymaps constantly to the buffer, checking if our keymaps have been overwritten, and then re-applying them if so. We could then apply the keymaps immediately, rather than waiting for CursorMoved. This would also fix #406

saghen avatar Sep 26 '25 13:09 saghen