Remove all default mappings
This commit is contained in:
18
README.md
18
README.md
@@ -79,17 +79,13 @@ lua <<EOF
|
||||
-- completion = cmp.config.window.bordered(),
|
||||
-- documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = {
|
||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
||||
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||
['<C-e>'] = cmp.mapping({
|
||||
i = cmp.mapping.abort(),
|
||||
c = cmp.mapping.close(),
|
||||
}),
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<C-e>'] = cmp.mapping.abort(),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||
},
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'vsnip' }, -- For vsnip users.
|
||||
@@ -112,6 +108,7 @@ lua <<EOF
|
||||
|
||||
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline('/', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
@@ -119,6 +116,7 @@ lua <<EOF
|
||||
|
||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
|
||||
18
doc/cmp.txt
18
doc/cmp.txt
@@ -91,18 +91,12 @@ NOTE:
|
||||
-- completion = cmp.config.window.bordered(),
|
||||
-- documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
mapping = {
|
||||
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
||||
['<C-e>'] = cmp.mapping({
|
||||
i = cmp.mapping.abort(),
|
||||
c = cmp.mapping.close(),
|
||||
}),
|
||||
-- Accept currently selected item. If none selected, `select` first item.
|
||||
-- Set `select` to `false` to only confirm explicitly selected items.
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping.complete(),
|
||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||
},
|
||||
}),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'vsnip' }, -- For vsnip users.
|
||||
@@ -116,6 +110,7 @@ NOTE:
|
||||
|
||||
-- `/` cmdline setup.
|
||||
cmp.setup.cmdline('/', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
@@ -123,6 +118,7 @@ NOTE:
|
||||
|
||||
-- `:` cmdline setup.
|
||||
cmp.setup.cmdline(':', {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
local compare = require('cmp.config.compare')
|
||||
local mapping = require('cmp.config.mapping')
|
||||
local keymap = require('cmp.utils.keymap')
|
||||
local types = require('cmp.types')
|
||||
|
||||
local WIDE_HEIGHT = 40
|
||||
@@ -18,66 +16,7 @@ return function()
|
||||
|
||||
preselect = types.cmp.PreselectMode.Item,
|
||||
|
||||
mapping = {
|
||||
['<Down>'] = mapping({
|
||||
i = mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Select }),
|
||||
c = function(fallback)
|
||||
local cmp = require('cmp')
|
||||
cmp.close()
|
||||
vim.schedule(cmp.suspend())
|
||||
fallback()
|
||||
end,
|
||||
}),
|
||||
['<Up>'] = mapping({
|
||||
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Select }),
|
||||
c = function(fallback)
|
||||
local cmp = require('cmp')
|
||||
cmp.close()
|
||||
vim.schedule(cmp.suspend())
|
||||
fallback()
|
||||
end,
|
||||
}),
|
||||
['<Tab>'] = mapping({
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if #cmp.core:get_sources() > 0 and not require('cmp.config').is_native_menu() then
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
else
|
||||
if vim.fn.pumvisible() == 0 then
|
||||
vim.api.nvim_feedkeys(keymap.t('<C-z>'), 'in', true)
|
||||
else
|
||||
vim.api.nvim_feedkeys(keymap.t('<C-n>'), 'in', true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
}),
|
||||
['<S-Tab>'] = mapping({
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if #cmp.core:get_sources() > 0 and not require('cmp.config').is_native_menu() then
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
else
|
||||
if vim.fn.pumvisible() == 0 then
|
||||
vim.api.nvim_feedkeys(keymap.t('<C-z><C-p><C-p>'), 'in', true)
|
||||
else
|
||||
vim.api.nvim_feedkeys(keymap.t('<C-p>'), 'in', true)
|
||||
end
|
||||
end
|
||||
end,
|
||||
}),
|
||||
['<C-n>'] = mapping(mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Insert }), { 'i', 'c' }),
|
||||
['<C-p>'] = mapping(mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert }), { 'i', 'c' }),
|
||||
['<C-y>'] = mapping.confirm({ select = false }),
|
||||
['<C-e>'] = mapping.abort(),
|
||||
},
|
||||
mapping = {},
|
||||
|
||||
snippet = {
|
||||
expand = function()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
local mapping
|
||||
mapping = setmetatable({}, {
|
||||
local types = require('cmp.types')
|
||||
local misc = require('cmp.utils.misc')
|
||||
|
||||
local mapping = setmetatable({}, {
|
||||
__call = function(_, invoke, modes)
|
||||
if type(invoke) == 'function' then
|
||||
local map = {}
|
||||
@@ -12,6 +14,59 @@ mapping = setmetatable({}, {
|
||||
end,
|
||||
})
|
||||
|
||||
---Mapping preset configuration.
|
||||
mapping.preset = {}
|
||||
|
||||
---Mapping preset insert-mode configuration.
|
||||
mapping.preset.insert = function(override)
|
||||
return misc.merge(override or {}, {
|
||||
['<Down>'] = {
|
||||
i = mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Select }),
|
||||
},
|
||||
['<Up>'] = {
|
||||
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Select }),
|
||||
},
|
||||
['<C-n>'] = {
|
||||
i = mapping.select_next_item({ behavior = types.cmp.SelectBehavior.Insert }),
|
||||
},
|
||||
['<C-p>'] = {
|
||||
i = mapping.select_prev_item({ behavior = types.cmp.SelectBehavior.Insert }),
|
||||
},
|
||||
['<C-y>'] = {
|
||||
i = mapping.confirm({ select = false }),
|
||||
},
|
||||
['<C-e>'] = {
|
||||
i = mapping.abort(),
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
---Mapping preset cmdline-mode configuration.
|
||||
mapping.preset.cmdline = function(override)
|
||||
return misc.merge(override or {}, {
|
||||
['<Tab>'] = {
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end
|
||||
},
|
||||
['<S-Tab>'] = {
|
||||
c = function()
|
||||
local cmp = require('cmp')
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
else
|
||||
cmp.complete()
|
||||
end
|
||||
end
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
---Invoke completion
|
||||
---@param option cmp.CompleteParams
|
||||
mapping.complete = function(option)
|
||||
|
||||
Reference in New Issue
Block a user