fix: modify nvim-cmp
This commit is contained in:
@@ -12,7 +12,7 @@ require('pluginconfig/neotest')
|
||||
require('pluginconfig/numb')
|
||||
require('pluginconfig/nvim-autopairs')
|
||||
require('pluginconfig/nvim-colorizer')
|
||||
require('pluginconfig/nvim-compe')
|
||||
require('pluginconfig/nvim-cmp')
|
||||
require('pluginconfig/fzf-lua')
|
||||
require('pluginconfig/nvim-tree') -- This plugin must be required somewhere before colorscheme. Placing it after will break navigation keymappings
|
||||
require('pluginconfig/nvim-treesitter')
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
local lspkind = require('lspkind')
|
||||
local cmp = require 'cmp'
|
||||
|
||||
local function keymapping(cmp)
|
||||
return {
|
||||
-- 上一个
|
||||
['<C-k>'] = cmp.mapping.select_prev_item(),
|
||||
-- 下一个
|
||||
['<C-j>'] = cmp.mapping.select_next_item(),
|
||||
-- 出现补全
|
||||
['<A-.>'] = cmp.mapping(cmp.mapping.complete(), { 'i', 'c' }),
|
||||
-- 取消
|
||||
['<A-,>'] = 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,
|
||||
behavior = cmp.ConfirmBehavior.Replace
|
||||
}),
|
||||
-- ['<C-y>'] = cmp.config.disable, -- Specify `cmp.config.disable` if you want to remove the default `<C-y>` mapping.
|
||||
['<C-u>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), { 'i', 'c' }),
|
||||
['<C-d>'] = cmp.mapping(cmp.mapping.scroll_docs(4), { 'i', 'c' }),
|
||||
}
|
||||
end
|
||||
|
||||
cmp.setup {
|
||||
-- 指定 snippet 引擎
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
-- For `vsnip` users.
|
||||
vim.fn["vsnip#anonymous"](args.body)
|
||||
|
||||
-- For `luasnip` users.
|
||||
-- require('luasnip').lsp_expand(args.body)
|
||||
|
||||
-- For `ultisnips` users.
|
||||
-- vim.fn["UltiSnips#Anon"](args.body)
|
||||
|
||||
-- For `snippy` users.
|
||||
-- require'snippy'.expand_snippet(args.body)
|
||||
end,
|
||||
},
|
||||
-- 来源
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'nvim_lsp' },
|
||||
-- For vsnip users.
|
||||
{ name = 'vsnip' },
|
||||
-- For luasnip users.
|
||||
-- { name = 'luasnip' },
|
||||
--For ultisnips users.
|
||||
-- { name = 'ultisnips' },
|
||||
-- -- For snippy users.
|
||||
-- { name = 'snippy' },
|
||||
}, { { name = 'buffer' },
|
||||
{ name = 'path' }
|
||||
}),
|
||||
|
||||
-- 快捷键
|
||||
mapping = keymapping(cmp),
|
||||
-- 使用lspkind-nvim显示类型图标
|
||||
formatting = {
|
||||
format = lspkind.cmp_format({
|
||||
with_text = true, -- do not show text alongside icons
|
||||
maxwidth = 50, -- prevent the popup from showing more than provided characters (e.g 50 will not show more than 50 characters)
|
||||
before = function(entry, vim_item)
|
||||
-- Source 显示提示来源
|
||||
vim_item.menu = "[" .. string.upper(entry.source.name) .. "]"
|
||||
return vim_item
|
||||
end
|
||||
})
|
||||
},
|
||||
}
|
||||
|
||||
-- Use buffer source for `/`.
|
||||
cmp.setup.cmdline('/', {
|
||||
sources = {
|
||||
{ name = 'buffer' }
|
||||
}
|
||||
})
|
||||
|
||||
-- Use cmdline & path source for ':'.
|
||||
cmp.setup.cmdline(':', {
|
||||
sources = cmp.config.sources({
|
||||
{ name = 'path' }
|
||||
}, {
|
||||
{ name = 'cmdline' }
|
||||
})
|
||||
})
|
||||
@@ -1,150 +0,0 @@
|
||||
vim.o.completeopt = "menuone,noselect"
|
||||
|
||||
require'compe'.setup {
|
||||
enabled = true,
|
||||
autocomplete = true,
|
||||
debug = false,
|
||||
min_length = 1,
|
||||
preselect = 'enable',
|
||||
throttle_time = 80,
|
||||
source_timeout = 200,
|
||||
incomplete_delay = 400,
|
||||
max_abbr_width = 100,
|
||||
max_kind_width = 100,
|
||||
max_menu_width = 100,
|
||||
documentation = true,
|
||||
|
||||
source = {
|
||||
path = {kind = " (Path)"},
|
||||
buffer = {kind = " (Buffer)"},
|
||||
calc = {kind = " (Calc)"},
|
||||
vsnip = {kind = " (Snippet)"},
|
||||
nvim_lsp = {kind = " (LSP)"},
|
||||
-- nvim_lua = {kind = " "},
|
||||
nvim_lua = false,
|
||||
spell = {kind = " (Spell)"},
|
||||
tags = false,
|
||||
vim_dadbod_completion = true,
|
||||
-- snippets_nvim = {kind = " "},
|
||||
-- ultisnips = {kind = " "},
|
||||
-- treesitter = {kind = " "},
|
||||
emoji = {kind = " ﲃ (Emoji)", filetypes={"markdown", "text"}}
|
||||
-- for emoji press : (idk if that in compe tho)
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
-- m
|
||||
--
|
||||
--
|
||||
--
|
||||
--
|
||||
|
||||
-- local t = function(str)
|
||||
-- return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||
-- end
|
||||
|
||||
-- local check_back_space = function()
|
||||
-- local col = vim.fn.col('.') - 1
|
||||
-- if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
|
||||
-- return true
|
||||
-- else
|
||||
-- return false
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- -- Use (s-)tab to:
|
||||
-- --- move to prev/next item in completion menuone
|
||||
-- --- jump to prev/next snippet's placeholder
|
||||
-- _G.tab_complete = function()
|
||||
-- if vim.fn.pumvisible() == 1 then
|
||||
-- return t "<C-n>"
|
||||
-- elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||
-- return t "<Plug>(vsnip-expand-or-jump)"
|
||||
-- elseif check_back_space() then
|
||||
-- return t "<Tab>"
|
||||
-- else
|
||||
-- return vim.fn['compe#complete']()
|
||||
-- end
|
||||
-- end
|
||||
-- _G.s_tab_complete = function()
|
||||
-- if vim.fn.pumvisible() == 1 then
|
||||
-- return t "<C-p>"
|
||||
-- elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
||||
-- return t "<Plug>(vsnip-jump-prev)"
|
||||
-- else
|
||||
-- return t "<S-Tab>"
|
||||
-- end
|
||||
-- end
|
||||
|
||||
-- vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
-- vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
-- vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||
-- vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
local t = function(str)
|
||||
return vim.api.nvim_replace_termcodes(str, true, true, true)
|
||||
end
|
||||
|
||||
local check_back_space = function()
|
||||
local col = vim.fn.col('.') - 1
|
||||
if col == 0 or vim.fn.getline('.'):sub(col, col):match('%s') then
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
-- Use (s-)tab to:
|
||||
--- move to prev/next item in completion menuone
|
||||
--- jump to prev/next snippet's placeholder
|
||||
_G.tab_complete = function()
|
||||
if vim.fn.pumvisible() == 1 then
|
||||
return t "<C-n>"
|
||||
elseif vim.fn.call("vsnip#available", {1}) == 1 then
|
||||
return t "<Plug>(vsnip-expand-or-jump)"
|
||||
elseif check_back_space() then
|
||||
return t "<Tab>"
|
||||
else
|
||||
return vim.fn['compe#complete']()
|
||||
end
|
||||
end
|
||||
_G.s_tab_complete = function()
|
||||
if vim.fn.pumvisible() == 1 then
|
||||
return t "<C-p>"
|
||||
elseif vim.fn.call("vsnip#jumpable", {-1}) == 1 then
|
||||
return t "<Plug>(vsnip-jump-prev)"
|
||||
else
|
||||
return t "<S-Tab>"
|
||||
end
|
||||
end
|
||||
|
||||
vim.api.nvim_set_keymap("i", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
vim.api.nvim_set_keymap("s", "<Tab>", "v:lua.tab_complete()", {expr = true})
|
||||
vim.api.nvim_set_keymap("i", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||
vim.api.nvim_set_keymap("s", "<S-Tab>", "v:lua.s_tab_complete()", {expr = true})
|
||||
Reference in New Issue
Block a user