nvim: update cmp config
This commit is contained in:
parent
ec86eb8ca3
commit
08616ba665
3 changed files with 104 additions and 97 deletions
|
@ -46,6 +46,8 @@ return require('packer').startup(function()
|
|||
end
|
||||
}
|
||||
|
||||
|
||||
-- cmp
|
||||
use {
|
||||
'hrsh7th/nvim-cmp',
|
||||
requires = {
|
||||
|
@ -57,104 +59,9 @@ return require('packer').startup(function()
|
|||
'L3MON4D3/LuaSnip',
|
||||
'saadparwaiz1/cmp_luasnip',
|
||||
},
|
||||
config = function()
|
||||
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
|
||||
|
||||
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]",
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
documentation = {
|
||||
border = 'rounded'
|
||||
},
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
|
||||
mapping = {
|
||||
['<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-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" }),
|
||||
},
|
||||
|
||||
sources = cmp.config.sources({
|
||||
{
|
||||
name = 'buffer',
|
||||
priority = 1,
|
||||
|
||||
},
|
||||
{
|
||||
name = 'luasnip',
|
||||
priority = 4,
|
||||
},
|
||||
{
|
||||
name = 'tmux',
|
||||
priority = 2,
|
||||
option = {
|
||||
all_panes = true,
|
||||
trigger_characters = {},
|
||||
}
|
||||
},
|
||||
{
|
||||
name = 'nvim_lsp',
|
||||
priority = 3,
|
||||
},
|
||||
})
|
||||
})
|
||||
|
||||
end
|
||||
config = function() require("plugins/nvim-cmp") end,
|
||||
}
|
||||
|
||||
|
||||
use {
|
||||
'lewis6991/gitsigns.nvim',
|
||||
requires = {
|
||||
|
|
98
.config/nvim/lua/plugins/nvim-cmp.lua
Normal file
98
.config/nvim/lua/plugins/nvim-cmp.lua
Normal file
|
@ -0,0 +1,98 @@
|
|||
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
|
||||
|
||||
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]",
|
||||
},
|
||||
}),
|
||||
},
|
||||
|
||||
window = {
|
||||
completion = cmp.config.window.bordered({
|
||||
winhighlight = 'Normal:PMenu,FloatBorder:PMenuBorder,CursorLine:PMenuSel,Search:None',
|
||||
}),
|
||||
documentation = cmp.config.window.bordered({
|
||||
winhighlight = 'Normal:PMenu,FloatBorder:PMenu,CursorLine:PMenuSel,Search:None',
|
||||
}),
|
||||
},
|
||||
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
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-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" }),
|
||||
},
|
||||
|
||||
sources = cmp.config.sources({
|
||||
{
|
||||
name = 'buffer',
|
||||
priority = 1,
|
||||
|
||||
},
|
||||
{
|
||||
name = 'luasnip',
|
||||
priority = 4,
|
||||
},
|
||||
{
|
||||
name = 'tmux',
|
||||
priority = 2,
|
||||
option = {
|
||||
all_panes = true,
|
||||
trigger_characters = {},
|
||||
}
|
||||
},
|
||||
{
|
||||
name = 'nvim_lsp',
|
||||
priority = 3,
|
||||
},
|
||||
})
|
||||
})
|
|
@ -39,7 +39,9 @@ local specs = lush.parse(function()
|
|||
GitSignsDeleteNr { fg = "#FFCDD2" },
|
||||
GitSignsChange { fg = "#FFA726" },
|
||||
GitSignsChangeNr { fg = "#FFE0B2" },
|
||||
PMenu { bg = "#BBDEFB" },
|
||||
|
||||
PMenu { bg = "#F7F5F0" },
|
||||
PMenuBorder { bg = "#F7F5F0", fg = "#886622" },
|
||||
PMenuSel { fg = "#FFFFFF", bg = "#1976D2" },
|
||||
PMenuSbar { bg = "#90CAF9" },
|
||||
PMenuThumb { bg = "#64B5F6" },
|
||||
|
|
Loading…
Reference in a new issue