diff --git a/vim/lua/nvim_cmp_config.lua b/vim/lua/nvim_cmp_config.lua index d005d08..7bfa7cf 100644 --- a/vim/lua/nvim_cmp_config.lua +++ b/vim/lua/nvim_cmp_config.lua @@ -1,10 +1,13 @@ local cmp = require("cmp") -- local cmp_buffer = require("cmp_buffer") +-- https://github.com/zbirenbaum/copilot-cmp#tab-completion-configuration-highly-recommended local has_words_before = function() - unpack = unpack or table.unpack + 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_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil + return col ~= 0 and vim.api.nvim_buf_get_text(0, line - 1, 0, line - 1, col, {})[1]:match("^%s*$") == nil end cmp.setup({ @@ -32,15 +35,13 @@ cmp.setup({ behavior = cmp.ConfirmBehavior.Insert, select = true, }), - [""] = function(fallback) - if not cmp.select_next_item() then - if vim.bo.buftype ~= "prompt" and has_words_before() then - cmp.complete() - else - fallback() - end + [""] = 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, + end), [""] = function(fallback) if not cmp.select_prev_item() then if vim.bo.buftype ~= "prompt" and has_words_before() then