add autopairs and create bindings for jumping through params in snippets

This commit is contained in:
2024-10-01 21:30:57 +02:00
parent b8e245dede
commit 7ab1449943
4 changed files with 28 additions and 7 deletions

View File

@@ -5,6 +5,26 @@ require("lazy").setup({
{ {
"hrsh7th/nvim-cmp", "hrsh7th/nvim-cmp",
dependencies = { dependencies = {
-- Code snippet engine
{
"L3MON4D3/LuaSnip",
version = "v2.*",
},
{
"windwp/nvim-autopairs",
opts = {
fast_wrap = {},
disable_filetype = { "TelescopePrompt", "vim" },
},
config = function(_, opts)
require("nvim-autopairs").setup(opts)
-- setup cmp for autopairs
local cmp_autopairs = require "nvim-autopairs.completion.cmp"
require("cmp").event:on("confirm_done", cmp_autopairs.on_confirm_done())
end,
},
"hrsh7th/cmp-nvim-lsp", -- lsp auto-completion "hrsh7th/cmp-nvim-lsp", -- lsp auto-completion
"hrsh7th/cmp-buffer", -- buffer auto-completion "hrsh7th/cmp-buffer", -- buffer auto-completion
"hrsh7th/cmp-path", -- path auto-completion "hrsh7th/cmp-path", -- path auto-completion
@@ -14,12 +34,6 @@ require("lazy").setup({
require("config.nvim-cmp") require("config.nvim-cmp")
end, end,
}, },
-- Code snippet engine
{
"L3MON4D3/LuaSnip",
version = "v2.*",
},
-- LSP manager -- LSP manager
"williamboman/mason.nvim", "williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim", "williamboman/mason-lspconfig.nvim",

View File

@@ -65,6 +65,8 @@ local on_attach = function(client, bufnr)
--end, bufopts) --end, bufopts)
end end
local capabilities = require("cmp_nvim_lsp").default_capabilities()
-- Configure each language -- Configure each language
-- How to add LSP for a specific language? -- How to add LSP for a specific language?
-- 1. use `:Mason` to install corresponding LSP -- 1. use `:Mason` to install corresponding LSP
@@ -73,5 +75,6 @@ end
for _, lsp in ipairs(servers) do for _, lsp in ipairs(servers) do
lspconfig[lsp].setup { lspconfig[lsp].setup {
on_attach = on_attach, on_attach = on_attach,
capabilities = capabilities,
} }
end end

View File

@@ -7,6 +7,9 @@ end
local luasnip = require("luasnip") local luasnip = require("luasnip")
local cmp = require("cmp") local cmp = require("cmp")
vim.keymap.set({ "i", "s" }, "<C-L>", function() luasnip.jump(1) end, { silent = true })
vim.keymap.set({ "i", "s" }, "<C-H>", function() luasnip.jump(-1) end, { silent = true })
cmp.setup({ cmp.setup({
snippet = { snippet = {
-- REQUIRED - you must specify a snippet engine -- REQUIRED - you must specify a snippet engine
@@ -76,4 +79,5 @@ cmp.setup({
{ name = 'buffer' }, -- For buffer word completion { name = 'buffer' }, -- For buffer word completion
{ name = 'path' }, -- For path completion { name = 'path' }, -- For path completion
}) })
}) })

View File

@@ -1,4 +1,4 @@
# TODO: # TODO:
- [x] commenting in normal / visual mode with '/' - [x] commenting in normal / visual mode with '/'
- [ ] autoclosing of brackets - [x] autoclosing of brackets
- [ ] type information in complete function - [ ] type information in complete function