Skip to content

Commit 340370d

Browse files
committed
feat: apply keymap on InsertEnter
closes #37
1 parent ab99b02 commit 340370d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lua/blink/cmp/keymap.lua

+8-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,10 @@ function keymap.setup(opts)
3939
end
4040
end
4141

42-
-- apply keymaps
4342
-- we set on the buffer directly to avoid buffer-local keymaps (such as from autopairs)
44-
-- from overriding our mappings
45-
keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands) -- apply immediately since the plugin starts asynchronously
46-
vim.api.nvim_create_autocmd('BufEnter', {
43+
-- from overriding our mappings. We also use InsertEnter to avoid conflicts with keymaps
44+
-- applied on other autocmds, such as LspAttach used by nvim-lspconfig and most configs
45+
vim.api.nvim_create_autocmd('InsertEnter', {
4746
callback = function() keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands) end,
4847
})
4948
end
@@ -52,6 +51,11 @@ end
5251
--- @param insert_keys_to_commands table<string, string[]>
5352
--- @param snippet_keys_to_commands table<string, string[]>
5453
function keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands)
54+
-- skip if we've already applied the keymaps
55+
for _, mapping in ipairs(vim.api.nvim_buf_get_keymap(0, 'i')) do
56+
if mapping.desc == 'blink.cmp' then return end
57+
end
58+
5559
-- insert mode: uses both snippet and insert commands
5660
for _, key in ipairs(utils.union_keys(insert_keys_to_commands, snippet_keys_to_commands)) do
5761
keymap.set('i', key, function()

0 commit comments

Comments
 (0)