--My personal completion. local api = vim.api local function before_words() local line = api.nvim_get_current_line() local col = api.nvim_win_get_cursor(0)[2] return line:sub(0, col) end local function luasnip_status() local ok, luasnip = pcall(require, 'luasnip') if not ok then return false end return luasnip.expand_or_jumpable() end local function map_tab() local words = before_words() if not words:match('%S') then return '' end if luasnip_status() then return 'luasnip-expand-or-jump' end if vim.fn.pumvisible() == 1 then return '' end local has_period = words:match('.') local has_slash = words:match('/') if not has_period and not has_slash then return '' elseif has_slash then return '' else return '' end end local function feedkeys(key, mode) local keycode = api.nvim_replace_termcodes(key, true, false, true) api.nvim_feedkeys(keycode, mode, false) end local function lua_func(item) if vim.bo.filetype == 'lua' and (item.kind == 'Field' or item.kind == 'Text') and item.word:find('nvim_') then return true end return false end local function insert_bracket() if not vim.v.completed_item or vim.tbl_isempty(vim.v.completed_item) then return end local item = vim.v.completed_item if (item.kind == 'Function' or lua_func(item)) and not item.word:find('%(') then feedkeys('()', 't') feedkeys('', 'n') end end local function map_cr() local npairs = require('nvim-autopairs') if vim.fn.pumvisible() == 1 then feedkeys('', 'n') insert_bracket() else local key = npairs.autopairs_cr() api.nvim_feedkeys(key, 'n', false) end end local mapped = false local function epoch() if mapped then return end local map = require('core.keymap') local opt = { expr = true, remap = true } map.i({ [''] = map_tab, [''] = map_cr }, opt) end return { epoch = epoch, }