Configuration for my NixOS based systems and Home Manager
1require("compe").setup(
2 {
3 enabled = true,
4 autocomplete = true,
5 debug = false,
6 min_length = 1,
7 preselect = "enable",
8 throttle_time = 80,
9 source_timeout = 200,
10 resolve_timeout = 800,
11 incomplete_delay = 400,
12 max_abbr_width = 100,
13 max_kind_width = 100,
14 max_menu_width = 100,
15 documentation = {
16 border = {"", "", "", " ", "", "", "", " "}, -- the border option is the same as `|help nvim_open_win|`
17 winhighlight = "NormalFloat:CompeDocumentation,FloatBorder:CompeDocumentationBorder",
18 max_width = 120,
19 min_width = 60,
20 max_height = math.floor(vim.o.lines * 0.3),
21 min_height = 1
22 },
23 source = {
24 path = true,
25 buffer = true,
26 calc = true,
27 nvim_lsp = true,
28 nvim_lua = true,
29 vsnip = true,
30 ultisnips = true,
31 luasnip = true
32 }
33 }
34)
35local t = function(str)
36 return vim.api.nvim_replace_termcodes(str, true, true, true)
37end
38
39local check_back_space = function()
40 local col = vim.fn.col(".") - 1
41 return col == 0 or vim.fn.getline("."):sub(col, col):match("%s") ~= nil
42end
43
44-- Use (s-)tab to:
45--- move to prev/next item in completion menuone
46--- jump to prev/next snippet's placeholder
47_G.tab_complete = function()
48 if vim.fn.pumvisible() == 1 then
49 return t "<C-n>"
50 elseif vim.fn["vsnip#available"](1) == 1 then
51 return t "<Plug>(vsnip-expand-or-jump)"
52 elseif check_back_space() then
53 return t "<Tab>"
54 else
55 return vim.fn["compe#complete"]()
56 end
57end
58_G.s_tab_complete = function()
59 if vim.fn.pumvisible() == 1 then
60 return t "<C-p>"
61 elseif vim.fn["vsnip#jumpable"](-1) == 1 then
62 return t "<Plug>(vsnip-jump-prev)"
63 else
64 -- If <S-Tab> is not working in your terminal, change it to <C-h>
65 return t "<S-Tab>"
66 end
67end
68
69vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
70vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
71vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
72vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})