40 lines
991 B
Lua
40 lines
991 B
Lua
vim.opt.completeopt = {'menu', 'menuone', 'noselect', 'noinsert'}
|
|
vim.opt.shortmess:append('c')
|
|
|
|
local function tab_complete()
|
|
if vim.fn.pumvisible() == 1 then
|
|
-- navigate to next item in completion menu
|
|
return '<Down>'
|
|
end
|
|
|
|
local c = vim.fn.col('.') - 1
|
|
local is_whitespace = c == 0 or vim.fn.getline('.'):sub(c, c):match('%s')
|
|
|
|
if is_whitespace then
|
|
-- insert tab
|
|
return '<Tab>'
|
|
end
|
|
|
|
local lsp_completion = vim.bo.omnifunc == 'v:lua.vim.lsp.omnifunc'
|
|
|
|
if lsp_completion then
|
|
-- trigger lsp code completion
|
|
return '<C-x><C-o>'
|
|
end
|
|
|
|
-- suggest words in current buffer
|
|
return '<C-x><C-n>'
|
|
end
|
|
|
|
local function tab_prev()
|
|
if vim.fn.pumvisible() == 1 then
|
|
-- navigate to previous item in completion menu
|
|
return '<Up>'
|
|
end
|
|
|
|
-- insert tab
|
|
return '<Tab>'
|
|
end
|
|
|
|
vim.keymap.set('i', '<Tab>', tab_complete, {expr = true})
|
|
vim.keymap.set('i', '<S-Tab>', tab_prev, {expr = true})
|