Update mapping configuration

This commit is contained in:
hrsh7th
2021-08-11 23:24:47 +09:00
parent 4c9462c28c
commit c2f872920e
8 changed files with 196 additions and 88 deletions

View File

@@ -33,6 +33,20 @@ lua <<EOF
vim.fn['vsnip#anonymous'](args.body)
end
},
-- You must set mapping.
mapping = {
['<C-p>'] = cmp.mapping.item.prev(),
['<C-n>'] = cmp.mapping.item.next(),
['<C-d>'] = cmp.mapping.scroll.up(),
['<C-f>'] = cmp.mapping.scroll.down(),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
-- You should specify your *installed* sources.
sources = {
@@ -56,23 +70,40 @@ The default configuration can be found in [here](./lua/cmp/config/default.lua)
You can use your own configuration like this:
```lua
require'cmp'.setup {
...
completion = {
autocomplete = { .. },
completeopt = 'menu,menuone,noselect',
keyword_pattern = [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]],
keyword_length = 1,
},
sorting = {
priority_weight = 2.,
comparators = { ... },
},
sources = { ... },
...
local cmp = require'cmp'
cmp.setup {
...
completion = {
autocomplete = { .. },
completeopt = 'menu,menuone,noselect',
keyword_pattern = [[\%(-\?\d\+\%(\.\d\+\)\?\|\h\w*\%(-\w*\)*\)]],
keyword_length = 1,
},
sorting = {
priority_weight = 2.,
comparators = { ... },
},
mapping = {
['<C-p>'] = cmp.mapping.item.prev(),
['<C-n>'] = cmp.mapping.item.next(),
['<C-d>'] = cmp.mapping.scroll.up(),
['<C-f>'] = cmp.mapping.scroll.down(),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = { ... },
...
}
```
### mapping (type: table<string, cmp.MappingConfig>)
Define mappings with `cmp.mapping` helper.
### completion.autocomplete (type: cmp.TriggerEvent[])
Which events should trigger `autocompletion`.
@@ -124,13 +155,13 @@ Each function must return `boolean|nil`.
Default:
```lua
{
compare.offset,
compare.exact,
compare.score,
compare.kind,
compare.sort_text,
compare.length,
compare.order,
compare.offset,
compare.exact,
compare.score,
compare.kind,
compare.sort_text,
compare.length,
compare.order,
}
```