init.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. --if not package.loaded['compe'] then
  2. -- return
  3. -- end
  4. local M = {}
  5. vim.g.vsnip_snippet_dir = O.vnsip_dir
  6. M.config = function()
  7. opt = {
  8. enabled = O.auto_complete,
  9. autocomplete = true,
  10. debug = false,
  11. min_length = 1,
  12. preselect = 'enable',
  13. throttle_time = 80,
  14. source_timeout = 200,
  15. incomplete_delay = 400,
  16. max_abbr_width = 100,
  17. max_kind_width = 100,
  18. max_menu_width = 100,
  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 = {kind = "  "},
  27. nvim_lua = false,
  28. spell = {kind = "  (Spell)"},
  29. tags = false,
  30. vim_dadbod_completion = true,
  31. -- snippets_nvim = {kind = "  "},
  32. -- ultisnips = {kind = "  "},
  33. -- treesitter = {kind = "  "},
  34. emoji = {kind = " ﲃ (Emoji)", filetypes={"markdown", "text"}}
  35. -- for emoji press : (idk if that in compe tho)
  36. }
  37. }
  38. if O.plugin.tabnine.active then
  39. opt.source.tabnine = {kind = " ", priority=200, max_reslts=6}
  40. end
  41. require'compe'.setup(opt)
  42. local t = function(str)
  43. return vim.api.nvim_replace_termcodes(str, true, true, true)
  44. end
  45. local check_back_space = function()
  46. local col = vim.fn.col('.') - 1
  47. if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
  48. return true
  49. else
  50. return false
  51. end
  52. end
  53. -- Use (s-)tab to:
  54. --- move to prev/next item in completion menuone
  55. --- jump to prev/next snippet's placeholder
  56. _G.tab_complete = function()
  57. if vim.fn.pumvisible() == 1 then
  58. return t "<C-n>"
  59. elseif vim.fn.call("vsnip#available", {1}) == 1 then
  60. return t "<Plug>(vsnip-expand-or-jump)"
  61. elseif check_back_space() then
  62. return t "<Tab>"
  63. else
  64. return vim.fn['compe#complete']()
  65. end
  66. end
  67. _G.s_tab_complete = function()
  68. if vim.fn.pumvisible() == 1 then
  69. return t "<C-p>"
  70. elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
  71. return t "<Plug>(vsnip-jump-prev)"
  72. else
  73. return t "<S-Tab>"
  74. end
  75. end
  76. vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
  77. vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
  78. vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
  79. vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
  80. vim.api.nvim_set_keymap("i", "<C-Space>", "compe#complete()", {noremap = true, silent = true, expr = true})
  81. vim.api.nvim_set_keymap("i", "<CR>", "compe#confirm('<CR>')", {noremap = true, silent = true, expr = true})
  82. vim.api.nvim_set_keymap("i", "<C-e>", "compe#close('<C-e>')", {noremap = true, silent = true, expr = true})
  83. vim.api.nvim_set_keymap("i", "<C-f>", "compe#scroll({ 'delta': +4 })", {noremap = true, silent = true, expr = true})
  84. vim.api.nvim_set_keymap("i", "<C-d>", "compe#scroll({ 'delta': -4 })", {noremap = true, silent = true, expr = true})
  85. end
  86. return M