neovim: cmp tweaks
This commit is contained in:
parent
cae9db14d4
commit
d4d72b615f
3 changed files with 350 additions and 366 deletions
|
@ -4,10 +4,10 @@ local M = {
|
|||
"andersevenrud/cmp-tmux",
|
||||
"hrsh7th/cmp-nvim-lsp",
|
||||
"hrsh7th/cmp-buffer",
|
||||
"hrsh7th/cmp-emoji",
|
||||
"hrsh7th/cmp-path",
|
||||
"hrsh7th/cmp-cmdline",
|
||||
"hrsh7th/cmp-nvim-lsp-signature-help",
|
||||
"L3MON4D3/LuaSnip",
|
||||
"onsails/lspkind-nvim",
|
||||
"saadparwaiz1/cmp_luasnip",
|
||||
},
|
||||
|
@ -16,26 +16,21 @@ local M = {
|
|||
|
||||
function M.config()
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
local has_words_before = function()
|
||||
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
|
||||
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
|
||||
end
|
||||
|
||||
vim.o.completeopt = "menuone,noselect"
|
||||
|
||||
cmp.setup({
|
||||
formatting = {
|
||||
format = require("lspkind").cmp_format({
|
||||
with_text = true,
|
||||
menu = {
|
||||
buffer = "[Buffer]",
|
||||
tmux = "[Tmux]",
|
||||
luasnip = "[LuaSnip]",
|
||||
nvim_lsp = "[LSP]",
|
||||
nvim_lua = "[Lua]",
|
||||
path = "[Path]",
|
||||
completion = {
|
||||
completeopt = "menu,menuone,noinsert",
|
||||
},
|
||||
}),
|
||||
|
||||
formatting = {
|
||||
format = require("lspkind").cmp_format(),
|
||||
},
|
||||
|
||||
window = {
|
||||
|
@ -49,50 +44,37 @@ function M.config()
|
|||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
require("luasnip").lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = {
|
||||
["<Up>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
|
||||
["<Down>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
|
||||
["<C-p>"] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }),
|
||||
["<C-n>"] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(-4),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(4),
|
||||
["<C-d>"] = cmp.mapping.scroll_docs(-2),
|
||||
["<C-u>"] = cmp.mapping.scroll_docs(2),
|
||||
["<C-e>"] = cmp.mapping({
|
||||
i = cmp.mapping.abort(),
|
||||
c = cmp.mapping.close(),
|
||||
}),
|
||||
["<CR>"] = cmp.mapping(cmp.mapping.confirm({ select = false }), { "i", "c" }),
|
||||
["<C-y>"] = cmp.mapping(cmp.mapping.confirm({ select = false }), { "i", "c" }),
|
||||
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
||||
["<Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_next_item()
|
||||
elseif luasnip.expand_or_locally_jumpable() then
|
||||
luasnip.expand_or_jump()
|
||||
elseif has_words_before() then
|
||||
cmp.complete()
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||
if cmp.visible() then
|
||||
cmp.select_prev_item()
|
||||
elseif luasnip.jumpable(-1) then
|
||||
luasnip.jump(-1)
|
||||
else
|
||||
fallback()
|
||||
end
|
||||
end, { "i", "s" }),
|
||||
-- ["<CR>"] = cmp.mapping(cmp.mapping.confirm({ select = false }), { "i", "c" }),
|
||||
-- ["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }),
|
||||
["<CR>"] = cmp.mapping(cmp.mapping.confirm({ select = true })),
|
||||
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), {}),
|
||||
},
|
||||
|
||||
-- experimental = {
|
||||
-- ghost_text = {
|
||||
-- hl_group = "LspCodeLens",
|
||||
-- },
|
||||
-- },
|
||||
|
||||
sources = cmp.config.sources({
|
||||
{ name = "buffer", priority = 1 },
|
||||
{ name = "luasnip", priority = 4 },
|
||||
{ name = "copilot", group_index = 5 },
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "nvim_lsp_signature_help" },
|
||||
{ name = "buffer" },
|
||||
{ name = "luasnip" },
|
||||
{ name = "copilot" },
|
||||
{
|
||||
name = "tmux",
|
||||
priority = 2,
|
||||
|
@ -101,8 +83,7 @@ function M.config()
|
|||
trigger_characters = {},
|
||||
},
|
||||
},
|
||||
{ name = "nvim_lsp", priority = 3 },
|
||||
{ name = "nvim_lsp_signature_help", priority = 4 },
|
||||
{ name = "emoji" },
|
||||
}),
|
||||
})
|
||||
end
|
||||
|
|
|
@ -57,6 +57,9 @@ function M.config()
|
|||
GitSignsChange({ fg = "#FFA726" }),
|
||||
GitSignsChangeNr({ fg = "#FFE0B2" }),
|
||||
|
||||
-- LspCodeLens({ fg = "#00ff00", gui = "undercurl" }),
|
||||
-- LspSignatureActiveParameter({ fg = "#ff0000", bg = "#ffffcc" }),
|
||||
|
||||
PMenu({ bg = "#F7F5F0" }),
|
||||
PMenuBorder({ bg = "#F7F5F0", fg = "#886622" }),
|
||||
PMenuSel({ fg = "#FFFFFF", bg = "#1976D2" }),
|
||||
|
|
Loading…
Reference in a new issue