11 "hrsh7th/cmp-path", |
11 "hrsh7th/cmp-path", |
12 "quangnguyen30192/cmp-nvim-tags", |
12 "quangnguyen30192/cmp-nvim-tags", |
13 }, |
13 }, |
14 config = function() |
14 config = function() |
15 local cmp = require("cmp") |
15 local cmp = require("cmp") |
16 local luasnip = require("luasnip") |
|
17 |
16 |
18 local has_words_before = function() |
17 local has_words_before = function() |
19 local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
18 local line, col = unpack(vim.api.nvim_win_get_cursor(0)) |
20 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil |
19 return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil |
21 end |
20 end |
43 ["<C-b>"] = cmp.mapping.scroll_docs(-4), |
42 ["<C-b>"] = cmp.mapping.scroll_docs(-4), |
44 ["<C-f>"] = cmp.mapping.scroll_docs(4), |
43 ["<C-f>"] = cmp.mapping.scroll_docs(4), |
45 ["<Tab>"] = cmp.mapping(function(fallback) |
44 ["<Tab>"] = cmp.mapping(function(fallback) |
46 if cmp.visible() then |
45 if cmp.visible() then |
47 cmp.select_next_item() |
46 cmp.select_next_item() |
48 elseif luasnip.expand_or_locally_jumpable() then |
47 elseif vim.snippet.active({direction = 1}) then |
49 luasnip.expand_or_jump() |
48 vim.snippet.jump(1) |
50 elseif has_words_before() then |
49 elseif has_words_before() then |
51 cmp.complete() |
50 cmp.complete() |
52 else |
51 else |
53 fallback() |
52 fallback() |
54 end |
53 end |
55 end, { "i", "s" }), |
54 end, { "i", "s" }), |
56 ["<S-Tab>"] = cmp.mapping(function(fallback) |
55 ["<S-Tab>"] = cmp.mapping(function(fallback) |
57 if cmp.visible() then |
56 if cmp.visible() then |
58 cmp.select_prev_item() |
57 cmp.select_prev_item() |
59 elseif luasnip.jumpable(-1) then |
58 elseif vim.snippet.active({direction = -1}) then |
60 luasnip.jump(-1) |
59 vim.snippet.jump(-1) |
61 else |
60 else |
62 fallback() |
61 fallback() |
63 end |
62 end |
64 end, { "i", "s" }), |
63 end, { "i", "s" }), |
65 ["<C-g>"] = cmp.mapping.abort(), |
64 ["<C-g>"] = cmp.mapping.abort(), |