compe.lua 3.0 KB

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