diff --git a/init.lua b/init.lua index 255098b2e62..a949941ad92 100644 --- a/init.lua +++ b/init.lua @@ -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) @@ -743,11 +751,17 @@ require('lazy').setup({ -- If you prefer more traditional completion keymaps, -- you can uncomment the following lines - [''] = cmp.mapping.select_next_item(), + [''] = 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), [''] = cmp.mapping.select_prev_item(), -- A less invasive - [''] = cmp.mapping.confirm { select = true }, + [''] = cmp.mapping.confirm { select = false }, -- Manually trigger a completion from nvim-cmp. -- Generally you don't need this, because nvim-cmp will display @@ -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, },