2021-09-09 19:55:32 +08:00
|
|
|
local remap = vim.api.nvim_set_keymap
|
|
|
|
local npairs = require('nvim-autopairs')
|
|
|
|
|
2022-04-03 23:22:30 +08:00
|
|
|
npairs.setup({map_bs = true, map_cr = true})
|
|
|
|
|
|
|
|
vim.g.coq_settings = {keymap = {recommended = false}}
|
2021-09-09 19:55:32 +08:00
|
|
|
|
|
|
|
-- these mappings are coq recommended mappings unrelated to nvim-autopairs
|
2021-10-25 12:10:08 +08:00
|
|
|
remap('i', '<esc>', [[pumvisible() ? "<c-e><esc>" : "<esc>"]],
|
|
|
|
{expr = true, noremap = true})
|
|
|
|
remap('i', '<c-c>', [[pumvisible() ? "<c-e><c-c>" : "<c-c>"]],
|
|
|
|
{expr = true, noremap = true})
|
|
|
|
remap('i', '<tab>', [[pumvisible() ? "<c-n>" : "<tab>"]],
|
|
|
|
{expr = true, noremap = true})
|
|
|
|
remap('i', '<s-tab>', [[pumvisible() ? "<c-p>" : "<bs>"]],
|
|
|
|
{expr = true, noremap = true})
|
2021-09-09 19:55:32 +08:00
|
|
|
|
|
|
|
-- skip it, if you use another global object
|
2021-10-25 12:10:08 +08:00
|
|
|
_G.MUtils = {}
|
2021-09-09 19:55:32 +08:00
|
|
|
|
|
|
|
MUtils.CR = function()
|
2021-10-25 12:10:08 +08:00
|
|
|
if vim.fn.pumvisible() ~= 0 then
|
|
|
|
if vim.fn.complete_info({'selected'}).selected ~= -1 then
|
|
|
|
return npairs.esc('<c-y>')
|
|
|
|
else
|
|
|
|
return npairs.esc('<c-e>') .. npairs.autopairs_cr()
|
|
|
|
end
|
2021-09-09 19:55:32 +08:00
|
|
|
else
|
2021-10-25 12:10:08 +08:00
|
|
|
return npairs.autopairs_cr()
|
2021-09-09 19:55:32 +08:00
|
|
|
end
|
|
|
|
end
|
2021-10-25 12:10:08 +08:00
|
|
|
remap('i', '<cr>', 'v:lua.MUtils.CR()', {expr = true, noremap = true})
|
2021-09-09 19:55:32 +08:00
|
|
|
|
|
|
|
MUtils.BS = function()
|
2021-10-25 12:10:08 +08:00
|
|
|
if vim.fn.pumvisible() ~= 0 and vim.fn.complete_info({'mode'}).mode ==
|
|
|
|
'eval' then
|
|
|
|
return npairs.esc('<c-e>') .. npairs.autopairs_bs()
|
|
|
|
else
|
|
|
|
return npairs.autopairs_bs()
|
|
|
|
end
|
2021-09-09 19:55:32 +08:00
|
|
|
end
|
2021-10-25 12:10:08 +08:00
|
|
|
remap('i', '<bs>', 'v:lua.MUtils.BS()', {expr = true, noremap = true})
|