refactor(vim): simplify the tab behaviour in completion
The biggest change here is that I am no longer cycling though completion items as the first thing. Tab will now mainly control the snippet jumps in completion not items. Completion items can be used exclusively with <C-n> and <C-p> and <CR> to complete the selected item. If the completion menu is open and <CR> is pressed, this will select and complete the first item. I will soon be able to remove the <C-h> and <C-l> mappings when my muscle memory adapts as this will now be controlled with tab.
This commit is contained in:
parent
a4e78a2c6a
commit
cc49f5339e
2 changed files with 3 additions and 23 deletions
|
|
@ -74,6 +74,3 @@ nnoremap <leader><tab> <c-^>
|
|||
" ignored from command-t file searches.
|
||||
let g:CommandTWildIgnore="*/node_modules/*,*/vendor/*,*/runtime/*,*/public_html/*,*/pack/*"
|
||||
|
||||
" Required for complietion with nvim-cmp
|
||||
set completeopt=menu,menuone,noselect
|
||||
|
||||
|
|
|
|||
|
|
@ -28,11 +28,6 @@ Text = "",
|
|||
Operator = "",
|
||||
}
|
||||
|
||||
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>'],
|
||||
|
|
@ -41,29 +36,17 @@ cmp.setup({
|
|||
['<C-h>'] = function() luasnip.jump(-1) end,
|
||||
|
||||
['<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' }),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_jumpable() then
|
||||
if 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
|
||||
if luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
|
|
|
|||
Loading…
Reference in a new issue