Skip to content

Commit 4ec5cea

Browse files
committed
feat: 'enter' keymap
1 parent fdf4846 commit 4ec5cea

File tree

3 files changed

+72
-6
lines changed

3 files changed

+72
-6
lines changed

README.md

+26-2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
opts = {
4949
-- 'default' for mappings similar to built-in completion
5050
-- 'super-tab' for mappings similar to vscode (tab to accept, arrow keys to navigate)
51+
-- 'enter' for mappings similar to 'super-tab' but with 'enter' to accept
5152
-- see the "default configuration" section below for full documentation on how to define
5253
-- your own keymap. when defining your own, no keybinds will be assigned automatically.
5354
keymap = 'default',
@@ -160,10 +161,15 @@ MiniDeps.add({
160161

161162
```lua
162163
{
163-
-- the keymap may be a preset ('default' | 'super-tab') OR a table of keys => command[]
164+
-- the keymap may be a preset ('default' | 'super-tab' | 'enter') OR a table of keys => command[]
164165
-- when defining your own, no keybinds will be assigned automatically.
165166
-- you may pass a function in the command array where returning true
166167
-- will prevent the next command from running
168+
--
169+
-- The "fallback" command will run the next non-blink keymap.
170+
-- For example, to accept the current completion item with "enter", or create a new line,
171+
-- when the blink window is closed, you would define it as:
172+
-- ['<CR>'] = { 'accept', 'fallback' }
167173
--
168174
-- "default" keymap
169175
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
@@ -184,7 +190,7 @@ MiniDeps.add({
184190
-- or use `window.autocomplete.selection = "manual" | "auto_insert"`
185191
--
186192
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
187-
-- ['<C-e>'] = { 'hide' },
193+
-- ['<C-e>'] = { 'hide', 'fallback' },
188194
--
189195
-- ['<Tab>'] = {
190196
-- function(cmp)
@@ -204,6 +210,24 @@ MiniDeps.add({
204210
-- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
205211
-- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
206212
--
213+
-- "enter" keymap
214+
-- you may want to set `window.autocomplete.selection = "manual" | "auto_insert"`
215+
--
216+
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
217+
-- ['<C-e>'] = { 'hide', 'fallback' },
218+
-- ['<CR>'] = { 'accept', 'fallback' },
219+
--
220+
-- ['<Tab>'] = { 'snippet_forward', 'fallback' },
221+
-- ['<S-Tab>'] = { 'snippet_backward', 'fallback' },
222+
--
223+
-- ['<Up>'] = { 'select_prev', 'fallback' },
224+
-- ['<Down>'] = { 'select_next', 'fallback' },
225+
-- ['<C-p>'] = { 'select_prev', 'fallback' },
226+
-- ['<C-n>'] = { 'select_next', 'fallback' },
227+
--
228+
-- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
229+
-- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
230+
--
207231
-- available commands:
208232
-- show, hide, accept, select_and_accept, select_prev, select_next, show_documentation, hide_documentation,
209233
-- scroll_documentation_up, scroll_documentation_down, snippet_forward, snippet_backward, fallback

lua/blink/cmp/config.lua

+27-4
Original file line numberDiff line numberDiff line change
@@ -167,11 +167,16 @@
167167

168168
--- @type blink.cmp.Config
169169
local config = {
170-
-- the keymap may be a preset ('default' | 'super-tab') or a table of keys => command[]
170+
-- the keymap may be a preset ('default' | 'super-tab' | 'enter') OR a table of keys => command[]
171171
-- when defining your own, no keybinds will be assigned automatically.
172-
-- additionally, you may pass a function in the command array where returning true
172+
-- you may pass a function in the command array where returning true
173173
-- will prevent the next command from running
174174
--
175+
-- The "fallback" command will run the next non-blink keymap.
176+
-- For example, to accept the current completion item with "enter", or create a new line,
177+
-- when the blink window is closed, you would define it as:
178+
-- ['<CR>'] = { 'accept', 'fallback' }
179+
--
175180
-- "default" keymap
176181
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
177182
-- ['<C-e>'] = { 'hide' },
@@ -187,11 +192,11 @@ local config = {
187192
-- ['<S-Tab>'] = { 'snippet_backward', 'fallback' },
188193
--
189194
-- "super-tab" keymap
190-
-- you may want to set `trigger.show_in_snippet = false` when using "super-tab"
195+
-- you may want to set `trigger.completion.show_in_snippet = false` when using "super-tab"
191196
-- or use `window.autocomplete.selection = "manual" | "auto_insert"`
192197
--
193198
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
194-
-- ['<C-e>'] = { 'hide' },
199+
-- ['<C-e>'] = { 'hide', 'fallback' },
195200
--
196201
-- ['<Tab>'] = {
197202
-- function(cmp)
@@ -211,6 +216,24 @@ local config = {
211216
-- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
212217
-- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
213218
--
219+
-- "enter" keymap
220+
-- you may want to set `window.autocomplete.selection = "manual" | "auto_insert"`
221+
--
222+
-- ['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
223+
-- ['<C-e>'] = { 'hide', 'fallback' },
224+
-- ['<CR>'] = { 'accept', 'fallback' },
225+
--
226+
-- ['<Tab>'] = { 'snippet_forward', 'fallback' },
227+
-- ['<S-Tab>'] = { 'snippet_backward', 'fallback' },
228+
--
229+
-- ['<Up>'] = { 'select_prev', 'fallback' },
230+
-- ['<Down>'] = { 'select_next', 'fallback' },
231+
-- ['<C-p>'] = { 'select_prev', 'fallback' },
232+
-- ['<C-n>'] = { 'select_next', 'fallback' },
233+
--
234+
-- ['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
235+
-- ['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
236+
--
214237
-- available commands:
215238
-- show, hide, accept, select_and_accept, select_prev, select_next, show_documentation, hide_documentation,
216239
-- scroll_documentation_up, scroll_documentation_down, snippet_forward, snippet_backward, fallback

lua/blink/cmp/keymap.lua

+19
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ local super_tab_keymap = {
4444
['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
4545
}
4646

47+
local enter_keymap = {
48+
['<C-space>'] = { 'show', 'show_documentation', 'hide_documentation' },
49+
['<C-e>'] = { 'hide' },
50+
['<CR>'] = { 'accept', 'fallback' },
51+
52+
['<Tab>'] = { 'snippet_forward', 'fallback' },
53+
['<S-Tab>'] = { 'snippet_backward', 'fallback' },
54+
55+
['<Up>'] = { 'select_prev', 'fallback' },
56+
['<Down>'] = { 'select_next', 'fallback' },
57+
['<C-p>'] = { 'select_prev', 'fallback' },
58+
['<C-n>'] = { 'select_next', 'fallback' },
59+
60+
['<C-b>'] = { 'scroll_documentation_up', 'fallback' },
61+
['<C-f>'] = { 'scroll_documentation_down', 'fallback' },
62+
}
63+
4764
local snippet_commands = { 'snippet_forward', 'snippet_backward' }
4865

4966
--- @param opts blink.cmp.KeymapConfig
@@ -79,6 +96,8 @@ function keymap.setup(opts)
7996
mappings = default_keymap
8097
elseif opts == 'super-tab' then
8198
mappings = super_tab_keymap
99+
elseif opts == 'enter' then
100+
mappings = enter_keymap
82101
else
83102
error('Invalid blink.cmp keymap preset: ' .. opts)
84103
end

0 commit comments

Comments
 (0)