completion.lua 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. return {
  2. { "hrsh7th/cmp-nvim-lsp" },
  3. {
  4. "L3MON4D3/LuaSnip",
  5. -- follow latest release.
  6. version = "v2.*", -- Replace <CurrentMajor> by the latest released major (first number of latest release)
  7. -- install jsregexp (optional!).
  8. build = "make install_jsregexp",
  9. dependencies = { "saadparwaiz1/cmp_luasnip", "rafamadriz/friendly-snippets" },
  10. },
  11. {
  12. "hrsh7th/nvim-cmp",
  13. dependencies = { "hrsh7th/cmp-buffer", "f3fora/cmp-spell", "hrsh7th/cmp-path", "hrsh7th/cmp-emoji", "R-nvim/cmp-r", "hrsh7th/cmp-nvim-lsp-signature-help" },
  14. config = function()
  15. local cmp = require("cmp")
  16. local luasnip = require("luasnip")
  17. require("luasnip.loaders.from_vscode").lazy_load()
  18. cmp.setup({
  19. snippet = {
  20. -- REQUIRED - you must specify a snippet engine
  21. expand = function(args)
  22. -- vim.fn["vsnip#anonymous"](args.body) -- For `vsnip` users.
  23. require("luasnip").lsp_expand(args.body) -- For `luasnip` users.
  24. -- require('snippy').expand_snippet(args.body) -- For `snippy` users.
  25. -- vim.fn["UltiSnips#Anon"](args.body) -- For `ultisnips` users.
  26. -- vim.snippet.expand(args.body) -- For native neovim snippets (Neovim v0.10+)
  27. end,
  28. },
  29. window = {
  30. -- completion = cmp.config.window.bordered(),
  31. -- documentation = cmp.config.window.bordered(),
  32. },
  33. mapping = cmp.mapping.preset.insert({
  34. ["<C-b>"] = cmp.mapping.scroll_docs(-4),
  35. ["<C-f>"] = cmp.mapping.scroll_docs(4),
  36. ["<C-Space>"] = cmp.mapping.complete(),
  37. ["<C-e>"] = cmp.mapping.abort(),
  38. ["<CR>"] = cmp.mapping(function(fallback)
  39. if cmp.visible() then
  40. if luasnip.expandable() then
  41. luasnip.expand()
  42. else
  43. cmp.confirm({
  44. select = true,
  45. })
  46. end
  47. else
  48. fallback()
  49. end
  50. end),
  51. ["<Tab>"] = cmp.mapping(function(fallback)
  52. if cmp.visible() then
  53. cmp.select_next_item()
  54. elseif luasnip.locally_jumpable(1) then
  55. luasnip.jump(1)
  56. else
  57. fallback()
  58. end
  59. end, { "i", "s" }),
  60. ["<S-Tab>"] = cmp.mapping(function(fallback)
  61. if cmp.visible() then
  62. cmp.select_prev_item()
  63. elseif luasnip.locally_jumpable(-1) then
  64. luasnip.jump(-1)
  65. else
  66. fallback()
  67. end
  68. end, { "i", "s" }),
  69. }),
  70. sources = cmp.config.sources({
  71. { name = "nvim_lsp" },
  72. { name = "buffer" },
  73. { name = "luasnip" }, -- For luasnip users.
  74. { name = 'emoji' },
  75. { name = "crates" }, -- cf rust
  76. { name = 'cmp_r' },
  77. { name = 'nvim_lsp_signature_help' },
  78. {
  79. name = "spell",
  80. option = {
  81. keep_all_entries = false,
  82. enable_in_context = function()
  83. return true
  84. end,
  85. preselect_correct_word = true,
  86. },
  87. },
  88. {
  89. name = "path",
  90. option = {
  91. -- Options go into this table
  92. },
  93. },
  94. -- { name = 'ultisnips' }, -- For ultisnips users.
  95. -- { name = 'snippy' }, -- For snippy users.
  96. }, {
  97. { name = "buffer" },
  98. }),
  99. })
  100. -- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
  101. -- Set configuration for specific filetype.
  102. --[[ cmp.setup.filetype('gitcommit', {
  103. sources = cmp.config.sources({
  104. { name = 'git' },
  105. }, {
  106. { name = 'buffer' },
  107. })
  108. })
  109. require("cmp_git").setup() ]]
  110. --
  111. -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
  112. cmp.setup.cmdline({ "/", "?" }, {
  113. mapping = cmp.mapping.preset.cmdline(),
  114. sources = {
  115. { name = "buffer" },
  116. },
  117. })
  118. -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
  119. -- cmp.setup.cmdline(":", {
  120. -- mapping = cmp.mapping.preset.cmdline(),
  121. -- sources = cmp.config.sources({
  122. -- { name = "path" },
  123. -- }, {
  124. -- { name = "cmdline" },
  125. -- }),
  126. -- matching = { disallow_symbol_nonprefix_matching = false },
  127. -- })
  128. end,
  129. },
  130. }