more cmp changes
This commit is contained in:
parent
cf05586a00
commit
8dedf49447
@ -1,5 +1,6 @@
|
||||
return {
|
||||
'hrsh7th/nvim-cmp',
|
||||
branch = 'main',
|
||||
lazy = false,
|
||||
dependencies = {
|
||||
'neovim/nvim-lspconfig',
|
||||
@ -11,10 +12,18 @@ return {
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
'onsails/lspkind.nvim',
|
||||
'zbirenbaum/copilot-cmp',
|
||||
'hrsh7th/cmp-path',
|
||||
'dmitmel/cmp-cmdline-history',
|
||||
'hrsh7th/cmp-nvim-lsp-signature-help',
|
||||
},
|
||||
config = function()
|
||||
local t = function(str)
|
||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||
end
|
||||
|
||||
local cmp = require('cmp')
|
||||
local lspkind = require('lspkind')
|
||||
local luasnip = require('luasnip')
|
||||
lspkind.init({
|
||||
symbol_map = {
|
||||
Copilot = '',
|
||||
@ -23,29 +32,75 @@ return {
|
||||
require('copilot_cmp').setup()
|
||||
|
||||
cmp.setup({
|
||||
preselect = cmp.PreselectMode.None,
|
||||
snippet = {
|
||||
-- REQUIRED - you must specify a snippet engine
|
||||
expand = function(args)
|
||||
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||
end,
|
||||
},
|
||||
mapping = {
|
||||
['<Up>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }),
|
||||
['<Down>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }),
|
||||
['<C-p>'] = cmp.mapping(cmp.mapping.select_prev_item(), { 'i', 'c', 's' }),
|
||||
['<C-n>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 'c', 's' }),
|
||||
['<C-d>'] = cmp.mapping.scroll_docs(-4),
|
||||
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||
['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c', 's' }),
|
||||
['<C-e>'] = cmp.mapping(cmp.mapping.close(), { 'i', 'c', 's' }),
|
||||
['<CR>'] = cmp.mapping({
|
||||
i = function(fallback)
|
||||
if cmp.visible() and cmp.get_active_entry() then
|
||||
cmp.confirm({ behavior = cmp.ConfirmBehavior.Insert, select = false })
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end,
|
||||
c = cmp.mapping.confirm({ select = false }),
|
||||
s = cmp.mapping.confirm({ select = false }),
|
||||
}),
|
||||
['<Tab>'] = cmp.mapping(function(fallback)
|
||||
if luasnip.expand_or_jumpable() then
|
||||
vim.api.nvim_feedkeys(t('<Plug>luasnip-expand-or-jump'), '', true)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, {
|
||||
'i',
|
||||
's',
|
||||
}),
|
||||
['<S-Tab>'] = cmp.mapping(function(fallback)
|
||||
if luasnip.jumpable(-1) then
|
||||
vim.api.nvim_feedkeys(t('<Plug>luasnip-jump-prev'), '', true)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { 'i', 's' }),
|
||||
['<c-x>'] = cmp.mapping(
|
||||
cmp.mapping.complete({
|
||||
config = {
|
||||
sources = {
|
||||
{
|
||||
name = 'cmdline_history',
|
||||
},
|
||||
},
|
||||
},
|
||||
}),
|
||||
{ 'c' }
|
||||
),
|
||||
},
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'copilot' },
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'nvim_lsp_signature_help' },
|
||||
{ name = 'luasnip' },
|
||||
{ name = 'buffer' },
|
||||
{ name = 'path' },
|
||||
}),
|
||||
|
||||
window = {
|
||||
completion = cmp.config.window.bordered(),
|
||||
documentation = cmp.config.window.bordered(),
|
||||
},
|
||||
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 = 'copilot' },
|
||||
{ name = 'nvim_lsp' },
|
||||
{ name = 'luasnip' }, -- For luasnip users.
|
||||
{ name = 'buffer' },
|
||||
}),
|
||||
formatting = {
|
||||
format = lspkind.cmp_format({
|
||||
mode = 'symbol',
|
||||
@ -60,33 +115,26 @@ return {
|
||||
},
|
||||
})
|
||||
|
||||
-- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
|
||||
-- Set configuration for specific filetype.
|
||||
--[[ cmp.setup.filetype('gitcommit', {
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'git' },
|
||||
}, {
|
||||
{ name = 'buffer' },
|
||||
})
|
||||
})
|
||||
require("cmp_git").setup() ]] --
|
||||
|
||||
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
||||
cmp.setup.cmdline({ '/', '?' }, {
|
||||
mapping = cmp.mapping.preset.cmdline(),
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
{ name = 'buffer' },
|
||||
{ name = 'cmdline_history' },
|
||||
{ name = 'path' },
|
||||
{ name = 'buffer' },
|
||||
}
|
||||
})
|
||||
|
||||
-- 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' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
}),
|
||||
sources = {
|
||||
{ name = 'cmdline', priority = 200 },
|
||||
{ name = 'path', priority = 3 },
|
||||
{ name = 'cmdline_history', priority = 3 },
|
||||
{ name = 'buffer', priority = 3 }
|
||||
},
|
||||
matching = { disallow_symbol_nonprefix_matching = false }
|
||||
})
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user