Skip to content

Commit

Permalink
less obtrusive completion bindings
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Suraci <[email protected]>
  • Loading branch information
vito committed Sep 10, 2024
1 parent 8defcc6 commit 31d7254
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ require('lazy').setup({
-- See `:help cmp`
local cmp = require 'cmp'

local has_words_before = function()
if vim.bo.buftype == 'prompt' then
return false
end
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match '^%s*$' == nil
end

cmp.setup {
snippet = {
expand = function(args)
Expand Down Expand Up @@ -743,11 +751,17 @@ require('lazy').setup({

-- If you prefer more traditional completion keymaps,
-- you can uncomment the following lines
['<Tab>'] = cmp.mapping.select_next_item(),
['<Tab>'] = vim.schedule_wrap(function(fallback)
if cmp.visible() and has_words_before() then
cmp.select_next_item { behavior = cmp.SelectBehavior.Select }
else
fallback()
end
end),
['<S-Tab>'] = cmp.mapping.select_prev_item(),

-- A less invasive <CR>
['<C-CR>'] = cmp.mapping.confirm { select = true },
['<CR>'] = cmp.mapping.confirm { select = false },

-- Manually trigger a completion from nvim-cmp.
-- Generally you don't need this, because nvim-cmp will display
Expand Down Expand Up @@ -782,6 +796,24 @@ require('lazy').setup({
{ name = 'path', group_index = 2 },
{ name = 'buffer', group_index = 3 },
},
sorting = {
priority_weight = 2,
comparators = {
require('copilot_cmp.comparators').prioritize,

-- Below is the default comparitor list and order for nvim-cmp
cmp.config.compare.offset,
-- cmp.config.compare.scopes, --this is commented in nvim-cmp too
cmp.config.compare.exact,
cmp.config.compare.score,
cmp.config.compare.recently_used,
cmp.config.compare.locality,
cmp.config.compare.kind,
cmp.config.compare.sort_text,
cmp.config.compare.length,
cmp.config.compare.order,
},
},
}
end,
},
Expand Down

0 comments on commit 31d7254

Please sign in to comment.