local keyset = vim.keymap.set -- Autocomplete function _G.check_back_space() local col = vim.fn.col('.') - 1 return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil end -- Use Tab for trigger completion with characters ahead and navigate -- NOTE: There's always a completion item selected by default, you may want to enable -- no select by setting `"suggest.noselect": true` in your configuration file -- NOTE: Use command ':verbose imap ' to make sure Tab is not mapped by -- other plugins before putting this into your config local opts = { silent = true, noremap = true, expr = true, replace_keycodes = false } -- keyset("i", "", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "" : coc#refresh()', opts) keyset("i", "", [[coc#pum#visible() ? coc#pum#prev(1) : "\"]], opts) -- Make to accept selected completion item or notify coc.nvim to format -- u breaks current undo, please make your own choice keyset("i", "", [[coc#pum#visible() ? coc#pum#confirm() : "\u\\=coc#on_enter()\"]], opts) -- Use to trigger snippets keyset("i", "", "(coc-snippets-expand-jump)") -- Use to trigger completion keyset("i", "", "coc#refresh()", {silent = true, expr = true}) -- Use `[g` and `]g` to navigate diagnostics -- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list keyset("n", "[g", "(coc-diagnostic-prev)", {silent = true}) keyset("n", "]g", "(coc-diagnostic-next)", {silent = true}) -- GoTo code navigation keyset("n", "gd", "(coc-definition)", {silent = true}) keyset("n", "gy", "(coc-type-definition)", {silent = true}) keyset("n", "gi", "(coc-implementation)", {silent = true}) keyset("n", "gr", "(coc-references)", {silent = true}) function _G.show_docs() local cw = vim.fn.expand('') if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then vim.api.nvim_command('h ' .. cw) elseif vim.api.nvim_eval('coc#rpc#ready()') then vim.fn.CocActionAsync('doHover') else vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw) end end keyset("n", "K", 'lua _G.show_docs()', {silent = true})