more cmp changes
This commit is contained in:
parent
cf05586a00
commit
8dedf49447
@ -1,5 +1,6 @@
|
|||||||
return {
|
return {
|
||||||
'hrsh7th/nvim-cmp',
|
'hrsh7th/nvim-cmp',
|
||||||
|
branch = 'main',
|
||||||
lazy = false,
|
lazy = false,
|
||||||
dependencies = {
|
dependencies = {
|
||||||
'neovim/nvim-lspconfig',
|
'neovim/nvim-lspconfig',
|
||||||
@ -11,10 +12,18 @@ return {
|
|||||||
'saadparwaiz1/cmp_luasnip',
|
'saadparwaiz1/cmp_luasnip',
|
||||||
'onsails/lspkind.nvim',
|
'onsails/lspkind.nvim',
|
||||||
'zbirenbaum/copilot-cmp',
|
'zbirenbaum/copilot-cmp',
|
||||||
|
'hrsh7th/cmp-path',
|
||||||
|
'dmitmel/cmp-cmdline-history',
|
||||||
|
'hrsh7th/cmp-nvim-lsp-signature-help',
|
||||||
},
|
},
|
||||||
config = function()
|
config = function()
|
||||||
|
local t = function(str)
|
||||||
|
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||||
|
end
|
||||||
|
|
||||||
local cmp = require('cmp')
|
local cmp = require('cmp')
|
||||||
local lspkind = require('lspkind')
|
local lspkind = require('lspkind')
|
||||||
|
local luasnip = require('luasnip')
|
||||||
lspkind.init({
|
lspkind.init({
|
||||||
symbol_map = {
|
symbol_map = {
|
||||||
Copilot = '',
|
Copilot = '',
|
||||||
@ -23,29 +32,75 @@ return {
|
|||||||
require('copilot_cmp').setup()
|
require('copilot_cmp').setup()
|
||||||
|
|
||||||
cmp.setup({
|
cmp.setup({
|
||||||
|
preselect = cmp.PreselectMode.None,
|
||||||
snippet = {
|
snippet = {
|
||||||
-- REQUIRED - you must specify a snippet engine
|
|
||||||
expand = function(args)
|
expand = function(args)
|
||||||
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
require('luasnip').lsp_expand(args.body) -- For `luasnip` users.
|
||||||
end,
|
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 = {
|
window = {
|
||||||
completion = cmp.config.window.bordered(),
|
completion = cmp.config.window.bordered(),
|
||||||
documentation = 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 = {
|
formatting = {
|
||||||
format = lspkind.cmp_format({
|
format = lspkind.cmp_format({
|
||||||
mode = 'symbol',
|
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).
|
-- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
|
||||||
cmp.setup.cmdline({ '/', '?' }, {
|
cmp.setup.cmdline({ '/', '?' }, {
|
||||||
mapping = cmp.mapping.preset.cmdline(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = {
|
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).
|
-- 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(),
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
sources = cmp.config.sources({
|
sources = {
|
||||||
{ name = 'path' }
|
{ name = 'cmdline', priority = 200 },
|
||||||
}, {
|
{ name = 'path', priority = 3 },
|
||||||
{ name = 'cmdline' }
|
{ name = 'cmdline_history', priority = 3 },
|
||||||
}),
|
{ name = 'buffer', priority = 3 }
|
||||||
|
},
|
||||||
matching = { disallow_symbol_nonprefix_matching = false }
|
matching = { disallow_symbol_nonprefix_matching = false }
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user