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(),
|
-- completion = cmp.config.window.bordered(),
|
||||||
-- documentation = cmp.config.window.bordered(),
|
-- documentation = cmp.config.window.bordered(),
|
||||||
},
|
},
|
||||||
mapping = {
|
mapping = cmp.mapping.preset.insert({
|
||||||
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
['<C-e>'] = cmp.mapping.abort(),
|
||||||
['<C-e>'] = cmp.mapping({
|
|
||||||
i = cmp.mapping.abort(),
|
|
||||||
c = cmp.mapping.close(),
|
|
||||||
}),
|
|
||||||
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
|
||||||
},
|
}),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
{ name = 'vsnip' }, -- For vsnip users.
|
{ 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).
|
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
|
||||||
cmp.setup.cmdline('/', {
|
cmp.setup.cmdline('/', {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = {
|
sources = {
|
||||||
{ name = 'buffer' }
|
{ name = 'buffer' }
|
||||||
}
|
}
|
||||||
@@ -119,6 +116,7 @@ lua <<EOF
|
|||||||
|
|
||||||
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
|
||||||
cmp.setup.cmdline(':', {
|
cmp.setup.cmdline(':', {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'path' }
|
{ name = 'path' }
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
18
doc/cmp.txt
18
doc/cmp.txt
@@ -91,18 +91,12 @@ NOTE:
|
|||||||
-- completion = cmp.config.window.bordered(),
|
-- completion = cmp.config.window.bordered(),
|
||||||
-- documentation = cmp.config.window.bordered(),
|
-- documentation = cmp.config.window.bordered(),
|
||||||
},
|
},
|
||||||
mapping = {
|
mapping = cmp.mapping.preset.insert({
|
||||||
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||||
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
['<C-Space>'] = cmp.mapping.complete(),
|
||||||
['<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.
|
|
||||||
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||||
},
|
}),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'nvim_lsp' },
|
{ name = 'nvim_lsp' },
|
||||||
{ name = 'vsnip' }, -- For vsnip users.
|
{ name = 'vsnip' }, -- For vsnip users.
|
||||||
@@ -116,6 +110,7 @@ NOTE:
|
|||||||
|
|
||||||
-- `/` cmdline setup.
|
-- `/` cmdline setup.
|
||||||
cmp.setup.cmdline('/', {
|
cmp.setup.cmdline('/', {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = {
|
sources = {
|
||||||
{ name = 'buffer' }
|
{ name = 'buffer' }
|
||||||
}
|
}
|
||||||
@@ -123,6 +118,7 @@ NOTE:
|
|||||||
|
|
||||||
-- `:` cmdline setup.
|
-- `:` cmdline setup.
|
||||||
cmp.setup.cmdline(':', {
|
cmp.setup.cmdline(':', {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = 'path' }
|
{ name = 'path' }
|
||||||
}, {
|
}, {
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
local compare = require('cmp.config.compare')
|
local compare = require('cmp.config.compare')
|
||||||
local mapping = require('cmp.config.mapping')
|
|
||||||
local keymap = require('cmp.utils.keymap')
|
|
||||||
local types = require('cmp.types')
|
local types = require('cmp.types')
|
||||||
|
|
||||||
local WIDE_HEIGHT = 40
|
local WIDE_HEIGHT = 40
|
||||||
@@ -18,66 +16,7 @@ return function()
|
|||||||
|
|
||||||
preselect = types.cmp.PreselectMode.Item,
|
preselect = types.cmp.PreselectMode.Item,
|
||||||
|
|
||||||
mapping = {
|
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(),
|
|
||||||
},
|
|
||||||
|
|
||||||
snippet = {
|
snippet = {
|
||||||
expand = function()
|
expand = function()
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
local mapping
|
local types = require('cmp.types')
|
||||||
mapping = setmetatable({}, {
|
local misc = require('cmp.utils.misc')
|
||||||
|
|
||||||
|
local mapping = setmetatable({}, {
|
||||||
__call = function(_, invoke, modes)
|
__call = function(_, invoke, modes)
|
||||||
if type(invoke) == 'function' then
|
if type(invoke) == 'function' then
|
||||||
local map = {}
|
local map = {}
|
||||||
@@ -12,6 +14,59 @@ mapping = setmetatable({}, {
|
|||||||
end,
|
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
|
---Invoke completion
|
||||||
---@param option cmp.CompleteParams
|
---@param option cmp.CompleteParams
|
||||||
mapping.complete = function(option)
|
mapping.complete = function(option)
|
||||||
|
|||||||
Reference in New Issue
Block a user