Add cmp.mapping.abort

This commit is contained in:
hrsh7th
2021-08-25 17:14:32 +09:00
parent 61eb3e0f10
commit 79601cb3db
3 changed files with 22 additions and 0 deletions

View File

@@ -136,6 +136,7 @@ mapping = {
- *cmp.mapping.scroll_docs(number)* - *cmp.mapping.scroll_docs(number)*
- *cmp.mapping.complete()* - *cmp.mapping.complete()*
- *cmp.mapping.close()* - *cmp.mapping.close()*
- *cmp.mapping.abort()*
- *cmp.mapping.confirm({ select = bool, behavior = cmp.ConfirmBehavior.{Insert,Replace} })* - *cmp.mapping.confirm({ select = bool, behavior = cmp.ConfirmBehavior.{Insert,Replace} })*
In addition, You can specify vim's mode to those mapping functions. In addition, You can specify vim's mode to those mapping functions.

View File

@@ -48,6 +48,18 @@ cmp.close = function()
end end
end end
---Abort current completion
cmp.abort = function()
if vim.fn.pumvisible() == 1 then
keymap.feedkeys(keymap.t('<C-e>'), 'n', function()
core.reset()
end)
return true;
else
return false
end
end
---Select next item if possible ---Select next item if possible
cmp.select_next_item = function() cmp.select_next_item = function()
if vim.fn.pumvisible() == 1 then if vim.fn.pumvisible() == 1 then

View File

@@ -28,6 +28,15 @@ mapping.close = function()
end end
end end
---Abort current completion menu if it displayed.
mapping.abort = function()
return function(fallback)
if not require('cmp').abort() then
fallback()
end
end
end
---Scroll documentation window. ---Scroll documentation window.
mapping.scroll_docs = function(delta) mapping.scroll_docs = function(delta)
return function(fallback) return function(fallback)