最終更新 1758768864

Confirm candidate on TAB immediately when there's only one completion entry

sajenim's Avatar sajenim revised this gist 1758768864. Go to revision

No changes

sajenim's Avatar sajenim revised this gist 1758768831. Go to revision

1 file changed, 18 insertions, 18 deletions

cmp.nix

@@ -1,19 +1,19 @@
1 - cmp.mapping(function(fallback)
2 - local line, col = unpack(vim.api.nvim_win_get_cursor(0))
1 + cmp.mapping(function(fallback)
2 + local line, col = unpack(vim.api.nvim_win_get_cursor(0))
3 3
4 - -- When the selection menu is open select the next item
5 - if cmp.visible() then
6 - cmp.select_next_item()
7 - -- Ensure we are mid word
8 - elseif col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil then
9 - -- Open the selection menu
10 - cmp.complete()
11 - -- Autocomplete when there is only 1 selection available
12 - if #cmp.get_entries() == 1 then
13 - cmp.confirm({ select = true })
14 - end
15 - -- Keep regular functionality of tab
16 - else
17 - fallback()
18 - end
19 - end, {'i', 's'})
4 + -- When the selection menu is open select the next item
5 + if cmp.visible() then
6 + cmp.select_next_item()
7 + -- Ensure we are mid word
8 + elseif col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil then
9 + -- Open the selection menu
10 + cmp.complete()
11 + -- Autocomplete when there is only 1 selection available
12 + if #cmp.get_entries() == 1 then
13 + cmp.confirm({ select = true })
14 + end
15 + -- Keep regular functionality of tab
16 + else
17 + fallback()
18 + end
19 + end, {'i', 's'})

sajenim's Avatar sajenim revised this gist 1758768688. Go to revision

1 file changed, 19 insertions

cmp.nix(file created)

@@ -0,0 +1,19 @@
1 + cmp.mapping(function(fallback)
2 + local line, col = unpack(vim.api.nvim_win_get_cursor(0))
3 +
4 + -- When the selection menu is open select the next item
5 + if cmp.visible() then
6 + cmp.select_next_item()
7 + -- Ensure we are mid word
8 + elseif col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil then
9 + -- Open the selection menu
10 + cmp.complete()
11 + -- Autocomplete when there is only 1 selection available
12 + if #cmp.get_entries() == 1 then
13 + cmp.confirm({ select = true })
14 + end
15 + -- Keep regular functionality of tab
16 + else
17 + fallback()
18 + end
19 + end, {'i', 's'})
Newer Older