diff --git a/.config/nvim/lua/pluginconf/nvim_cmp.lua b/.config/nvim/lua/pluginconf/nvim_cmp.lua index 477b339..f1c2399 100644 --- a/.config/nvim/lua/pluginconf/nvim_cmp.lua +++ b/.config/nvim/lua/pluginconf/nvim_cmp.lua @@ -1,4 +1,10 @@ local cmp = require "cmp" +local luasnip = require "luasnip" + +local function has_words_before() + 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 +end cmp.setup { snippet = { @@ -11,7 +17,17 @@ cmp.setup { [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.select_next_item()), + [""] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.select_next_item() + elseif luasnip.expand_or_jumpable() then + luasnip.expand_or_jump() + elseif has_words_before() then + cmp.complete() + else + fallback() + end + end, { "i", "s" }), [""] = cmp.mapping(cmp.mapping.select_prev_item()), [""] = cmp.mapping.confirm { select = true }, },