diff --git a/config/nvim/init.lua b/config/nvim/init.lua index bf302bd..8cf591a 100644 --- a/config/nvim/init.lua +++ b/config/nvim/init.lua @@ -136,21 +136,19 @@ require('lazy').setup({ }, }, + { + 'zbirenbaum/copilot.lua', + config = function() + require('copilot').setup { + suggestion = { enabled = false }, + panel = { enabled = false }, + filetypes = { markdown = true }, + } + end, + }, + { 'zbirenbaum/copilot-cmp', - event = { 'BufRead', 'BufNewFile' }, - dependencies = { - { - 'zbirenbaum/copilot.lua', - config = function() - require('copilot').setup { - suggestion = { enabled = false }, - panel = { enabled = false }, - filetypes = { markdown = true }, - } - end, - }, - }, config = function() require('copilot_cmp').setup() end, }, @@ -680,7 +678,11 @@ local cmp_opts = { border = "solid", winhighlight = 'Normal:Pmenu,FloatBorder:FloatBorder,Search:NONE,CursorLine:PmenuSel', } - +local has_words_before = function() + if vim.api.nvim_buf_get_option(0, "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 { preselect = cmp.PreselectMode.None, view = { @@ -712,7 +714,7 @@ cmp.setup { select = false, }, [''] = cmp.mapping(function(fallback) - if cmp.visible() then + if cmp.visible() and has_words_before() then cmp.select_next_item() elseif luasnip.expand_or_locally_jumpable() then luasnip.expand_or_jump() @@ -731,11 +733,11 @@ cmp.setup { end, { 'i', 's' }), }, sources = { - { name = 'nvim_lsp', priority = 2000 }, - { name = 'luasnip', priority = 1000 }, - { name = 'copilot', priority = 750 }, - { name = 'buffer', priority = 500 }, - { name = 'path', priority = 250 }, + { name = 'copilot', priority = 2 }, + { name = 'nvim_lsp', priority = 2 }, + { name = 'buffer', priority = 2 }, + { name = 'path', priority = 2 }, + { name = 'luasnip', priority = 2 }, }, }