coc.lua 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. local keyset = vim.keymap.set
  2. -- Autocomplete
  3. function _G.check_back_space()
  4. local col = vim.fn.col('.') - 1
  5. return col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') ~= nil
  6. end
  7. -- Use Tab for trigger completion with characters ahead and navigate
  8. -- NOTE: There's always a completion item selected by default, you may want to enable
  9. -- no select by setting `"suggest.noselect": true` in your configuration file
  10. -- NOTE: Use command ':verbose imap <tab>' to make sure Tab is not mapped by
  11. -- other plugins before putting this into your config
  12. local opts = { silent = true, noremap = true, expr = true, replace_keycodes = false }
  13. -- keyset("i", "<TAB>", 'coc#pum#visible() ? coc#pum#next(1) : v:lua.check_back_space() ? "<TAB>" : coc#refresh()', opts)
  14. keyset("i", "<S-TAB>", [[coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"]], opts)
  15. -- Make <CR> to accept selected completion item or notify coc.nvim to format
  16. -- <C-g>u breaks current undo, please make your own choice
  17. keyset("i", "<TAB>", [[coc#pum#visible() ? coc#pum#confirm() : "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"]], opts)
  18. -- Use <c-j> to trigger snippets
  19. keyset("i", "<c-j>", "<Plug>(coc-snippets-expand-jump)")
  20. -- Use <c-space> to trigger completion
  21. keyset("i", "<c-space>", "coc#refresh()", {silent = true, expr = true})
  22. -- Use `[g` and `]g` to navigate diagnostics
  23. -- Use `:CocDiagnostics` to get all diagnostics of current buffer in location list
  24. keyset("n", "[g", "<Plug>(coc-diagnostic-prev)", {silent = true})
  25. keyset("n", "]g", "<Plug>(coc-diagnostic-next)", {silent = true})
  26. -- GoTo code navigation
  27. keyset("n", "gd", "<Plug>(coc-definition)", {silent = true})
  28. keyset("n", "gy", "<Plug>(coc-type-definition)", {silent = true})
  29. keyset("n", "gi", "<Plug>(coc-implementation)", {silent = true})
  30. keyset("n", "gr", "<Plug>(coc-references)", {silent = true})
  31. function _G.show_docs()
  32. local cw = vim.fn.expand('<cword>')
  33. if vim.fn.index({'vim', 'help'}, vim.bo.filetype) >= 0 then
  34. vim.api.nvim_command('h ' .. cw)
  35. elseif vim.api.nvim_eval('coc#rpc#ready()') then
  36. vim.fn.CocActionAsync('doHover')
  37. else
  38. vim.api.nvim_command('!' .. vim.o.keywordprg .. ' ' .. cw)
  39. end
  40. end
  41. keyset("n", "K", '<CMD>lua _G.show_docs()<CR>', {silent = true})