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.
|
" ignored from command-t file searches.
|
||||||
let g:CommandTWildIgnore="*/node_modules/*,*/vendor/*,*/runtime/*,*/public_html/*,*/pack/*"
|
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 = "",
|
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({
|
cmp.setup({
|
||||||
mapping = cmp.mapping.preset.insert({
|
mapping = cmp.mapping.preset.insert({
|
||||||
['<C-j>'] = cmp.get_config().mapping['<Down>'],
|
['<C-j>'] = cmp.get_config().mapping['<Down>'],
|
||||||
|
|
@ -41,29 +36,17 @@ cmp.setup({
|
||||||
['<C-h>'] = function() luasnip.jump(-1) end,
|
['<C-h>'] = function() luasnip.jump(-1) end,
|
||||||
|
|
||||||
['<C-e>'] = cmp.mapping.abort(),
|
['<C-e>'] = cmp.mapping.abort(),
|
||||||
['<CR>'] = cmp.mapping(function(_fallback)
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||||
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)
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if luasnip.expand_or_jumpable() then
|
||||||
cmp.select_next_item()
|
|
||||||
elseif luasnip.expand_or_jumpable() then
|
|
||||||
luasnip.expand_or_jump()
|
luasnip.expand_or_jump()
|
||||||
elseif has_words_before() then
|
|
||||||
cmp.complete()
|
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { "i", "s" }),
|
||||||
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if luasnip.jumpable(-1) then
|
||||||
cmp.select_prev_item()
|
|
||||||
elseif luasnip.jumpable(-1) then
|
|
||||||
luasnip.jump(-1)
|
luasnip.jump(-1)
|
||||||
else
|
else
|
||||||
fallback()
|
fallback()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue