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 '' 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 '' end local lsp_completion = vim.bo.omnifunc == 'v:lua.vim.lsp.omnifunc' if lsp_completion then -- trigger lsp code completion return '' end -- suggest words in current buffer return '' end local function tab_prev() if vim.fn.pumvisible() == 1 then -- navigate to previous item in completion menu return '' end -- insert tab return '' end vim.keymap.set('i', '', tab_complete, {expr = true}) vim.keymap.set('i', '', tab_prev, {expr = true})