nvim-cmp: cleanup, lazyload, add source for "/" "?" ":"
This commit is contained in:
parent
2e3d61dd1f
commit
4f5fa9b471
1 changed files with 26 additions and 19 deletions
|
@ -13,7 +13,8 @@ return {
|
||||||
"rafamadriz/friendly-snippets", -- pre-configured snippet texts
|
"rafamadriz/friendly-snippets", -- pre-configured snippet texts
|
||||||
"saadparwaiz1/cmp_luasnip", -- nvim-cmp source
|
"saadparwaiz1/cmp_luasnip", -- nvim-cmp source
|
||||||
},
|
},
|
||||||
init = function()
|
event = { "InsertEnter", "CmdlineEnter" },
|
||||||
|
opts = function()
|
||||||
local cmp = require("cmp")
|
local cmp = require("cmp")
|
||||||
local luasnip = require("luasnip")
|
local luasnip = require("luasnip")
|
||||||
local has_words_before = function()
|
local has_words_before = function()
|
||||||
|
@ -24,25 +25,14 @@ return {
|
||||||
|
|
||||||
require("mason").setup()
|
require("mason").setup()
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
require("luasnip.loaders.from_vscode").lazy_load()
|
||||||
require("cmp").setup({
|
|
||||||
|
cmp.setup({
|
||||||
-- keybinds
|
-- keybinds
|
||||||
mapping = cmp.mapping.preset.insert({
|
-- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
|
||||||
-- unsure
|
mapping = {
|
||||||
["<C-b>"] = cmp.mapping.scroll_docs(-4),
|
|
||||||
["<C-f>"] = cmp.mapping.scroll_docs(4),
|
|
||||||
["<C-o>"] = cmp.mapping.complete(),
|
|
||||||
["<C-e>"] = cmp.mapping.abort(),
|
|
||||||
|
|
||||||
-- return to confirm
|
|
||||||
["<CR>"] = cmp.mapping.confirm({ select = false }),
|
|
||||||
|
|
||||||
-- tab to select prev/next option
|
|
||||||
-- see: https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings#luasnip
|
|
||||||
["<Tab>"] = cmp.mapping(function(fallback)
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_next_item()
|
cmp.select_next_item()
|
||||||
-- You could replace the expand_or_jumpable() calls with expand_or_locally_jumpable()
|
|
||||||
-- that way you will only jump inside the snippet region
|
|
||||||
elseif luasnip.expand_or_jumpable() then
|
elseif luasnip.expand_or_jumpable() then
|
||||||
luasnip.expand_or_jump()
|
luasnip.expand_or_jump()
|
||||||
elseif has_words_before() then
|
elseif has_words_before() then
|
||||||
|
@ -51,6 +41,7 @@ return {
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { "i", "s" }),
|
||||||
|
|
||||||
["<S-Tab>"] = cmp.mapping(function(fallback)
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
if cmp.visible() then
|
if cmp.visible() then
|
||||||
cmp.select_prev_item()
|
cmp.select_prev_item()
|
||||||
|
@ -60,7 +51,7 @@ return {
|
||||||
fallback()
|
fallback()
|
||||||
end
|
end
|
||||||
end, { "i", "s" }),
|
end, { "i", "s" }),
|
||||||
}),
|
},
|
||||||
|
|
||||||
-- snippet engine
|
-- snippet engine
|
||||||
snippet = {
|
snippet = {
|
||||||
|
@ -69,14 +60,30 @@ return {
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
|
||||||
-- snippet source
|
-- completion source
|
||||||
sources = cmp.config.sources({
|
sources = cmp.config.sources({
|
||||||
{ name = "nvim_lsp" },
|
{ name = "nvim_lsp" },
|
||||||
{ name = "luasnip" },
|
{ name = "luasnip" },
|
||||||
}, {
|
|
||||||
{ name = "buffer" },
|
{ name = "buffer" },
|
||||||
{ name = "path" },
|
{ name = "path" },
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Use buffer source for `/` and `?`
|
||||||
|
cmp.setup.cmdline({ "/", "?" }, {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
|
sources = {
|
||||||
|
{ name = "buffer" },
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- Use cmdline & path source for ':'
|
||||||
|
cmp.setup.cmdline(":", {
|
||||||
|
mapping = cmp.mapping.preset.cmdline(),
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = "path" },
|
||||||
|
{ name = "cmdline" },
|
||||||
|
}),
|
||||||
|
})
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue