Add autopairs to nvim-cmp
This commit is contained in:
@@ -2,8 +2,8 @@ return function()
|
|||||||
local km = vim.keymap.set
|
local km = vim.keymap.set
|
||||||
local opts = {}
|
local opts = {}
|
||||||
|
|
||||||
opts.desc = "show documentation under cursor"
|
opts.desc = "show help documentation under cursor"
|
||||||
km("n", "<leader>lK", vim.lsp.buf.hover, opts)
|
km("n", "<leader>lh", vim.lsp.buf.hover, opts)
|
||||||
|
|
||||||
opts.desc = "show LSP References"
|
opts.desc = "show LSP References"
|
||||||
km("n", "<leader>lR", ":Telescope lsp_references<cr>", opts)
|
km("n", "<leader>lR", ":Telescope lsp_references<cr>", opts)
|
||||||
@@ -24,7 +24,7 @@ return function()
|
|||||||
km({ "n", "v" }, "<leader>lc", vim.lsp.buf.code_action, opts)
|
km({ "n", "v" }, "<leader>lc", vim.lsp.buf.code_action, opts)
|
||||||
|
|
||||||
opts.desc = "Smart rename"
|
opts.desc = "Smart rename"
|
||||||
km("n", "<leader>ln", vim.lsp.buf.rename, opts)
|
km("n", "<leader>lr", vim.lsp.buf.rename, opts)
|
||||||
|
|
||||||
opts.desc = "Show buffer diagnostics"
|
opts.desc = "Show buffer diagnostics"
|
||||||
km("n", "<leader>lE", ":Telescope diagnostics bufnr=0<cr>", opts)
|
km("n", "<leader>lE", ":Telescope diagnostics bufnr=0<cr>", opts)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
--- Ensure plugin is avaiable
|
--- Ensure plugin is avaiable
|
||||||
local ok, nvimautopairs = pcall(require, "nvim-autopairs")
|
local ok, nvimautopairs = pcall(require, "nvim-autopairs")
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
--- Ensure plugins are installed
|
--- Ensure plugins are installed
|
||||||
local ok, cmp, luasnip, lspkind = pcall(function()
|
local ok, cmp, luasnip, luasnip_from_vscode, lspkind, cmp_autopairs = pcall(function()
|
||||||
return require("cmp"), require("luasnip"), require("lspkind")
|
return require("cmp"),
|
||||||
|
require("luasnip"),
|
||||||
|
require("luasnip.loaders.from_vscode"),
|
||||||
|
require("lspkind"),
|
||||||
|
require("nvim-autopairs.completion.cmp")
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not ok then
|
if not ok then
|
||||||
@@ -8,8 +12,9 @@ if not ok then
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
--- loads vscode style snippets from installed plugins (e.g. friendly-snippets)
|
||||||
require("luasnip.loaders.from_vscode").lazy_load()
|
luasnip_from_vscode.lazy_load()
|
||||||
|
|
||||||
|
--- Plugin options
|
||||||
local opts = {
|
local opts = {
|
||||||
completion = {
|
completion = {
|
||||||
completeopt = "menu,menuone,preview,noselect",
|
completeopt = "menu,menuone,preview,noselect",
|
||||||
@@ -40,4 +45,24 @@ local opts = {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--- Load plugin
|
||||||
cmp.setup(opts)
|
cmp.setup(opts)
|
||||||
|
|
||||||
|
--- Add autopairs
|
||||||
|
|
||||||
|
cmp.event:on(
|
||||||
|
"confirm_done",
|
||||||
|
cmp_autopairs.on_confirm_done({
|
||||||
|
filetypes = {
|
||||||
|
-- "*" is a alias to all filetypes
|
||||||
|
["*"] = {
|
||||||
|
["("] = {
|
||||||
|
kind = {
|
||||||
|
cmp.lsp.CompletionItemKind.Function,
|
||||||
|
cmp.lsp.CompletionItemKind.Method,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user