Another copy of my dotfiles. Because I don't completely trust GitHub.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.9 KiB

  1. local has_words_before = function()
  2. unpack = unpack or table.unpack
  3. local line, col = unpack(vim.api.nvim_win_get_cursor(0))
  4. return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
  5. end
  6. return function()
  7. local cmp = require'cmp'
  8. local snippy = require("snippy")
  9. local lspkind = require('lspkind')
  10. cmp.setup({
  11. snippet = {
  12. expand = function(args)
  13. require('snippy').expand_snippet(args.body) -- For `snippy` users.
  14. end,
  15. },
  16. window = {
  17. completion = cmp.config.window.bordered(),
  18. documentation = cmp.config.window.bordered(),
  19. },
  20. mapping = cmp.mapping.preset.insert({
  21. ['<C-b>'] = cmp.mapping.scroll_docs(-4),
  22. ['<C-f>'] = cmp.mapping.scroll_docs(4),
  23. ['<C-Space>'] = cmp.mapping.complete(),
  24. ['<C-e>'] = cmp.mapping.abort(),
  25. ["<CR>"] = cmp.mapping({
  26. i = function(fallback)
  27. if cmp.visible() and cmp.get_active_entry() then
  28. cmp.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false })
  29. else
  30. fallback()
  31. end
  32. end,
  33. s = cmp.mapping.confirm({ select = false }),
  34. c = cmp.mapping.confirm({ behavior = cmp.ConfirmBehavior.Replace, select = false }),
  35. }),
  36. ["<Tab>"] = cmp.mapping(function(fallback)
  37. if cmp.visible() then
  38. cmp.select_next_item()
  39. elseif snippy.can_expand_or_advance() then
  40. snippy.expand_or_advance()
  41. elseif has_words_before() then
  42. cmp.complete()
  43. else
  44. fallback()
  45. end
  46. end, { "i", "s" }),
  47. ["<S-Tab>"] = cmp.mapping(function(fallback)
  48. if cmp.visible() then
  49. cmp.select_prev_item()
  50. elseif snippy.can_jump(-1) then
  51. snippy.previous()
  52. else
  53. fallback()
  54. end
  55. end, { "i", "s" }),
  56. }),
  57. sources = cmp.config.sources({
  58. { name = "copilot" },
  59. { name = 'nvim_lsp' },
  60. { name = 'snippy' },
  61. { name = 'vimtex', },
  62. { name = 'path' },
  63. }, {
  64. { name = 'buffer' },
  65. }),
  66. formatting = {
  67. format = lspkind.cmp_format({
  68. mode = 'symbol_text',
  69. preset = 'codicons',
  70. maxwidth = 50,
  71. ellipsis_char = '...',
  72. before = function (entry, vim_item)
  73. return vim_item
  74. end,
  75. symbol_map = { Copilot = "" },
  76. })
  77. }
  78. })
  79. cmp.setup.filetype('gitcommit', {
  80. sources = cmp.config.sources({
  81. { name = 'git' },
  82. }, {
  83. { name = 'buffer' },
  84. })
  85. })
  86. cmp.setup.cmdline({ '/', '?' }, {
  87. mapping = cmp.mapping.preset.cmdline(),
  88. view = {
  89. entries = {name = 'wildmenu', separator = '|' }
  90. },
  91. sources = {
  92. { name = 'buffer' },
  93. { name = 'path' }
  94. }
  95. })
  96. cmp.setup.cmdline(':', {
  97. mapping = cmp.mapping.preset.cmdline(),
  98. sources = cmp.config.sources({
  99. { name = 'path' }
  100. }, {
  101. { name = 'cmdline' }
  102. })
  103. })
  104. end