Skip to content
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

disable blink.cmp remaps when telescope prompt is open #104

13 changes: 13 additions & 0 deletions lua/blink/cmp/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local cmp = {}
--- @param opts blink.cmp.Config
cmp.setup = function(opts)
local config = require('blink.cmp.config')
local utils = require('blink.cmp.utils')
config.merge_with(opts)

require('blink.cmp.fuzzy.download').ensure_downloaded(function(err)
Expand All @@ -13,6 +14,18 @@ cmp.setup = function(opts)

cmp.add_default_highlights()

-- disable blinkcmp if there is a special buffer e.g. prompt
-- prompt is used by many plugins like telescope
vim.api.nvim_create_autocmd({ 'BufEnter', 'InsertEnter' }, {
callback = function()
if utils.is_special_buffer() then
vim.g.blinkcmp_enabled = false
return
end
vim.g.blinkcmp_enabled = true
end,
})

scottmckendry marked this conversation as resolved.
Show resolved Hide resolved
require('blink.cmp.keymap').setup(config.keymap)

-- STRUCTURE
Expand Down
6 changes: 5 additions & 1 deletion lua/blink/cmp/keymap.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
local utils = require('blink.cmp.utils')
local config = require('blink.cmp.config')
local keymap = {}

local insert_commands = {
Expand Down Expand Up @@ -43,7 +44,10 @@ function keymap.setup(opts)
-- from overriding our mappings. We also use InsertEnter to avoid conflicts with keymaps
-- applied on other autocmds, such as LspAttach used by nvim-lspconfig and most configs
vim.api.nvim_create_autocmd('InsertEnter', {
callback = function() keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands) end,
callback = function()
if not vim.g.blinkcmp_enabled then return end
scottmckendry marked this conversation as resolved.
Show resolved Hide resolved
keymap.apply_keymap_to_current_buffer(insert_keys_to_commands, snippet_keys_to_commands)
end,
})
end

Expand Down
4 changes: 4 additions & 0 deletions lua/blink/cmp/trigger/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ function trigger.activate_autocmds()
-- decide if we should show the completion window
vim.api.nvim_create_autocmd('TextChangedI', {
callback = function()
if not vim.g.blinkcmp_enabled then return end

scottmckendry marked this conversation as resolved.
Show resolved Hide resolved
-- we were told to ignore the text changed event, so we update the context
-- but don't send an on_show event upstream
if trigger.ignore_next_text_changed then
Expand Down Expand Up @@ -61,6 +63,8 @@ function trigger.activate_autocmds()

vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
callback = function(ev)
if not vim.g.blinkcmp_enabled then return end

-- we were told to ignore the cursor moved event, so we update the context
-- but don't send an on_show event upstream
if trigger.ignore_next_cursor_moved and ev.event == 'CursorMovedI' then
Expand Down
4 changes: 4 additions & 0 deletions lua/blink/cmp/trigger/signature.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ function trigger.activate_autocmds()
-- decide if we should show the completion window
vim.api.nvim_create_autocmd('TextChangedI', {
callback = function()
if not vim.g.blinkcmp_enabled then return end

scottmckendry marked this conversation as resolved.
Show resolved Hide resolved
-- no characters added so let cursormoved handle it
if #last_chars == 0 then return end

Expand Down Expand Up @@ -60,6 +62,8 @@ function trigger.activate_autocmds()
-- check if we've moved outside of the context by diffing against the query boundary
vim.api.nvim_create_autocmd({ 'CursorMovedI', 'InsertEnter' }, {
callback = function(ev)
if not vim.g.blinkcmp_enabled then return end

-- characters added so let textchanged handle it
if #last_chars ~= 0 then return end

Expand Down