btw i use nix
1local cmp = require 'cmp'
2
3cmp.setup {
4 snippet = {
5 expand = function(args)
6 require('luasnip').lsp_expand(args.body)
7 end,
8 },
9 formatting = {
10 format = function(entry, vim_item)
11 vim_item.menu = ({
12 omni = '[Omni]',
13 nvim_lsp = '[LSP]',
14 nvim_lsp_signature_help = '[Signature]',
15 dictionary = '[Dictionary]',
16 buffer = '[Buffer]',
17 path = '[Path]',
18 ls = '[Luasnip]',
19 orgmode = '[Orgmode]',
20 })[entry.source.name]
21 return vim_item
22 end,
23 },
24 mapping = {
25 ['<C-y>'] = {
26 i = cmp.mapping.confirm({ select = false }),
27 c = cmp.mapping.confirm({ select = false }),
28 },
29 ['<C-e>'] = {
30 i = cmp.mapping.abort(),
31 c = cmp.mapping.abort(),
32 },
33 ['<C-Space>'] = {
34 i = cmp.mapping.complete(),
35 c = cmp.mapping.complete(),
36 },
37 ['<Down>'] = {
38 i = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
39 c = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Insert }),
40 },
41 ['<Up>'] = {
42 i = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
43 c = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Insert }),
44 },
45 },
46 sources = cmp.config.sources({
47 { name = 'orgmode', priority = 1100 },
48 { name = 'nvim_lsp_signature_help', priority = 1000 },
49 { name = 'nvim_lsp', priority = 900 },
50 { name = 'luasnip', priority = 800 },
51 { name = 'omni', priority = 700 },
52 { name = 'buffer', priority = 600 },
53 { name = 'path', priority = 500 },
54 {
55 name = 'dictionary',
56 priority = 400,
57 keyword_length = 2,
58 }
59 ,
60 }),
61 sorting = {
62 priority_weight = 2,
63 comparators = {
64 cmp.config.compare.offset,
65 -- cmp.config.compare.scopes,
66 cmp.config.compare.score,
67 cmp.config.compare.recently_used,
68 cmp.config.compare.locality,
69 cmp.config.compare.kind,
70 -- cmp.config.compare.sort_text,
71 -- cmp.config.compare.length,
72 cmp.config.compare.order,
73 },
74 },
75}
76-- `/` cmdline setup.
77cmp.setup.cmdline('/', {
78 sources = {
79 { name = 'buffer' }
80 },
81 completion = {
82 autocomplete = false
83 }
84})
85-- `:` cmdline setup.
86cmp.setup.cmdline(':', {
87 sources = cmp.config.sources({
88 { name = 'path' }
89 }, {
90 { name = 'cmdline' }
91 }),
92 completion = {
93 autocomplete = false
94 }
95})