Dotfiles/site-modules/core/files/vim/plugin/completion.lua
Ade Attwood 68c1b1ba32 chore(vim): add mapping to exit completion
This is when inside a snippet the tab get taken over by the completion
menu, you can then not jump to the next mark in the snippet.

Now you can use <C-e> to close the completion menu and tab will then
jump to the next mark in the snippet.
2022-07-10 21:11:42 +01:00

56 lines
1.6 KiB
Lua

local cmp = require'cmp'
local luasnip = require'luasnip'
local has_words_before = function()
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({
mapping = cmp.mapping.preset.insert({
['<C-j>'] = cmp.get_config().mapping['<Down>'],
['<C-k>'] = cmp.get_config().mapping['<Up>'],
['<C-e>'] = cmp.mapping.abort(),
['<CR>'] = cmp.mapping(function(_fallback)
if cmp.visible() then
cmp.confirm({ select = true })
else
vim.api.nvim_feedkeys('\n', 'nt', false)
end
end, { 'i', 's' }),
["<Tab>"] = 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" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
}),
sources = {
{ name = "luasnip" },
{ name = 'nvim_lsp' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'orgmode' }
},
snippet = {
expand = function(args)
luasnip.lsp_expand(args.body)
end,
},
})