1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
require('nvim-autopairs').setup()
local npairs = require('nvim-autopairs')
local function imap(lhs, rhs, opts)
local options = {noremap = false}
if opts then options = vim.tbl_extend('force', options, opts) end
vim.api.nvim_set_keymap('i', lhs, rhs, options)
end
_G.MUtils = {}
-- TEST
vim.g.completion_confirm_key = ""
MUtils.completion_confirm = function()
if vim.fn.pumvisible() ~= 0 then
if vim.fn.complete_info()["selected"] ~= -1 then
vim.fn["compe#confirm"]()
-- return npairs.esc("<c-y>")
return npairs.esc("")
else
vim.defer_fn(function()
vim.fn["compe#confirm"]("<cr>")
end, 20)
return npairs.esc("<c-n>")
end
else
return npairs.check_break_line_char()
end
end
-- TEST
MUtils.completion_confirm = function()
if vim.fn.pumvisible() ~= 0 then
if vim.fn.complete_info()["selected"] ~= -1 then
vim.fn["compe#confirm"]()
return npairs.esc("")
else
vim.api.nvim_select_popupmenu_item(0, false, false, {})
vim.fn["compe#confirm"]()
return npairs.esc("<c-n>")
end
else
return npairs.check_break_line_char()
end
end
MUtils.tab = function()
if vim.fn.pumvisible() ~= 0 then
return npairs.esc("<C-n>")
else
if vim.fn["vsnip#available"](1) ~= 0 then
vim.fn.feedkeys(string.format('%c%c%c(vsnip-expand-or-jump)', 0x80, 253, 83))
return npairs.esc("")
else
return npairs.esc("<Tab>")
end
end
end
MUtils.s_tab = function()
if vim.fn.pumvisible() ~= 0 then
return npairs.esc("<C-p>")
else
if vim.fn["vsnip#jumpable"](-1) ~= 0 then
vim.fn.feedkeys(string.format('%c%c%c(vsnip-jump-prev)', 0x80, 253, 83))
return npairs.esc("")
else
return npairs.esc("<C-h>")
end
end
end
-- Autocompletion and snippets
vim.api.nvim_set_keymap('i', '<CR>', 'v:lua.MUtils.completion_confirm()', {expr = true, noremap = true})
-- imap("<CR>", "v:lua.MUtils.completion_confirm()", {expr = true, noremap = true})
imap("<Tab>", "v:lua.MUtils.tab()", {expr = true, noremap = true})
imap("<S-Tab>", "v:lua.MUtils.s_tab()", {expr = true, noremap = true})
|