compe.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. local M = {}
  2. M.config = function()
  3. lvim.builtin.compe = {
  4. enabled = true,
  5. autocomplete = true,
  6. debug = false,
  7. min_length = 1,
  8. preselect = "enable",
  9. throttle_time = 80,
  10. source_timeout = 200,
  11. incomplete_delay = 400,
  12. max_abbr_width = 100,
  13. max_kind_width = 100,
  14. max_menu_width = 100,
  15. documentation = {
  16. border = "single",
  17. winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
  18. },
  19. -- documentation = true,
  20. source = {
  21. path = { kind = "  (Path)" },
  22. buffer = { kind = "  (Buffer)" },
  23. calc = { kind = "  (Calc)" },
  24. vsnip = { kind = "  (Snippet)" },
  25. nvim_lsp = { kind = "  (LSP)" },
  26. nvim_lua = false,
  27. spell = { kind = "  (Spell)" },
  28. tags = false,
  29. vim_dadbod_completion = false,
  30. snippets_nvim = false,
  31. ultisnips = false,
  32. treesitter = false,
  33. emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } },
  34. -- for emoji press : (idk if that in compe tho)
  35. },
  36. }
  37. end
  38. M.setup = function()
  39. vim.g.vsnip_snippet_dir = lvim.vsnip_dir
  40. local status_ok, compe = pcall(require, "compe")
  41. if not status_ok then
  42. return
  43. end
  44. compe.setup(lvim.builtin.compe)
  45. local t = function(str)
  46. return vim.api.nvim_replace_termcodes(str, true, true, true)
  47. end
  48. local check_back_space = function()
  49. local col = vim.fn.col "." - 1
  50. if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then
  51. return true
  52. else
  53. return false
  54. end
  55. end
  56. local remap = vim.api.nvim_set_keymap
  57. remap("i", "<Tab>", 'pumvisible() ? "<C-n>" : "<Tab>"', { silent = true, noremap = true, expr = true })
  58. remap("i", "<S-Tab>", 'pumvisible() ? "<C-p>" : "<S-Tab>"', { silent = true, noremap = true, expr = true })
  59. -- Use (s-)tab to:
  60. --- move to prev/next item in completion menuone
  61. --- jump to prev/next snippet's placeholder
  62. _G.tab_complete = function()
  63. if vim.fn.pumvisible() == 1 then
  64. return t "<C-n>"
  65. elseif vim.fn.call("vsnip#available", { 1 }) == 1 then
  66. return t "<Plug>(vsnip-expand-or-jump)"
  67. elseif check_back_space() then
  68. return t "<Tab>"
  69. else
  70. return vim.fn["compe#complete"]()
  71. end
  72. end
  73. _G.s_tab_complete = function()
  74. if vim.fn.pumvisible() == 1 then
  75. return t "<C-p>"
  76. elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then
  77. return t "<Plug>(vsnip-jump-prev)"
  78. else
  79. return t "<S-Tab>"
  80. end
  81. end
  82. vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", { noremap = true, silent = true, expr = true })
  83. -- vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", { noremap = true, silent = true, expr = true })
  84. vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", { noremap = true, silent = true, expr = true })
  85. vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", { noremap = true, silent = true, expr = true })
  86. vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", { noremap = true, silent = true, expr = true })
  87. end
  88. return M