@@ -26,10 +26,20 @@ function keymap.merge_mappings(existing_mappings, new_mappings)
26
26
return merged_mappings
27
27
end
28
28
29
- --- @param keymap_config blink.cmp.KeymapConfig
30
- function keymap .get_mappings (keymap_config )
29
+ --- @param keymap_config blink.cmp.KeymapConfig
30
+ --- @param mode blink.cmp.Mode
31
+ function keymap .get_mappings (keymap_config , mode )
31
32
local mappings = vim .deepcopy (keymap_config )
32
33
34
+ -- Remove unused keys
35
+ if mode ~= ' default' then
36
+ for key , commands in pairs (mappings ) do
37
+ if key ~= ' preset' and not require (' blink.cmp.keymap.apply' ).has_insert_command (commands ) then
38
+ mappings [key ] = nil
39
+ end
40
+ end
41
+ end
42
+
33
43
-- Handle preset
34
44
if mappings .preset then
35
45
local preset_keymap = require (' blink.cmp.keymap.presets' ).get (mappings .preset )
@@ -48,7 +58,7 @@ function keymap.setup()
48
58
local config = require (' blink.cmp.config' )
49
59
local apply = require (' blink.cmp.keymap.apply' )
50
60
51
- local mappings = keymap .get_mappings (config .keymap )
61
+ local mappings = keymap .get_mappings (config .keymap , ' default ' )
52
62
53
63
-- We set on the buffer directly to avoid buffer-local keymaps (such as from autopairs)
54
64
-- from overriding our mappings. We also use InsertEnter to avoid conflicts with keymaps
@@ -70,14 +80,14 @@ function keymap.setup()
70
80
for _ , mode in ipairs ({ ' cmdline' , ' term' }) do
71
81
local mode_config = config [mode ]
72
82
if mode_config .enabled then
73
- local mode_keymap = mode_config .keymap
83
+ local mode_keymap = vim . deepcopy ( mode_config .keymap )
74
84
75
85
if mode_config .keymap .preset == ' inherit' then
76
86
mode_keymap = vim .tbl_deep_extend (' force' , config .keymap , mode_config .keymap )
77
87
mode_keymap .preset = config .keymap .preset
78
88
end
79
89
80
- local mode_mappings = keymap .get_mappings (mode_keymap )
90
+ local mode_mappings = keymap .get_mappings (mode_keymap , mode )
81
91
apply [mode .. ' _keymaps' ](mode_mappings )
82
92
end
83
93
end
0 commit comments