compe.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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. max_width = 120,
  19. min_width = 60,
  20. max_height = math.floor(vim.o.lines * 0.3),
  21. min_height = 1,
  22. },
  23. -- documentation = true,
  24. source = {
  25. path = { kind = "  (Path)" },
  26. buffer = { kind = "  (Buffer)" },
  27. calc = { kind = "  (Calc)" },
  28. vsnip = { kind = "  (Snippet)" },
  29. nvim_lsp = { kind = "  (LSP)" },
  30. nvim_lua = false,
  31. spell = { kind = "  (Spell)" },
  32. tags = false,
  33. vim_dadbod_completion = false,
  34. snippets_nvim = false,
  35. ultisnips = false,
  36. treesitter = false,
  37. emoji = { kind = " ﲃ (Emoji)", filetypes = { "markdown", "text" } },
  38. -- for emoji press : (idk if that in compe tho)
  39. },
  40. keymap = {
  41. values = {
  42. insert_mode = {
  43. ["<Tab>"] = { 'pumvisible() ? "<C-n>" : "<Tab>"' },
  44. ["<S-Tab>"] = { 'pumvisible() ? "<C-p>" : "<S-Tab>"' },
  45. ["<C-Space>"] = { "compe#complete()" },
  46. ["<C-e>"] = { "compe#close('<C-e>')" },
  47. ["<C-f>"] = { "compe#scroll({ 'delta': +4 })" },
  48. ["<C-d>"] = { "compe#scroll({ 'delta': -4 })" },
  49. },
  50. },
  51. opts = {
  52. insert_mode = { noremap = true, silent = true, expr = true },
  53. },
  54. },
  55. }
  56. end
  57. M.setup = function()
  58. vim.g.vsnip_snippet_dir = lvim.vsnip_dir
  59. local status_ok, compe = pcall(require, "compe")
  60. if not status_ok then
  61. return
  62. end
  63. compe.setup(lvim.builtin.compe)
  64. local t = function(str)
  65. return vim.api.nvim_replace_termcodes(str, true, true, true)
  66. end
  67. local check_back_space = function()
  68. local col = vim.fn.col "." - 1
  69. if col == 0 or vim.fn.getline("."):sub(col, col):match "%s" then
  70. return true
  71. else
  72. return false
  73. end
  74. end
  75. -- Use (s-)tab to:
  76. --- move to prev/next item in completion menuone
  77. --- jump to prev/next snippet's placeholder
  78. _G.tab_complete = function()
  79. if vim.fn.pumvisible() == 1 then
  80. return t "<C-n>"
  81. elseif vim.fn.call("vsnip#available", { 1 }) == 1 then
  82. return t "<Plug>(vsnip-expand-or-jump)"
  83. elseif check_back_space() then
  84. return t "<Tab>"
  85. else
  86. return vim.fn["compe#complete"]()
  87. end
  88. end
  89. _G.s_tab_complete = function()
  90. if vim.fn.pumvisible() == 1 then
  91. return t "<C-p>"
  92. elseif vim.fn.call("vsnip#jumpable", { -1 }) == 1 then
  93. return t "<Plug>(vsnip-jump-prev)"
  94. else
  95. return t "<S-Tab>"
  96. end
  97. end
  98. local keymap = require "utils.keymap"
  99. keymap.load(lvim.builtin.compe.keymap.values, lvim.builtin.compe.keymap.opts)
  100. end
  101. return M