From c8af8e107a01a8612f2fb91e169eb50c398b2bcc Mon Sep 17 00:00:00 2001 From: Kai Chevannes Date: Wed, 13 Nov 2024 19:57:25 +0000 Subject: [PATCH] feat: add auto pairing and multiple cursor plugins --- lazy-lock.json | 8 +- lua/plugins/autopairs.lua | 7 ++ lua/plugins/lspzero.lua | 230 +++++++++++++++++++---------------- lua/plugins/visual-multi.lua | 3 + 4 files changed, 138 insertions(+), 110 deletions(-) create mode 100644 lua/plugins/autopairs.lua create mode 100644 lua/plugins/visual-multi.lua diff --git a/lazy-lock.json b/lazy-lock.json index 26e9245..b964cff 100644 --- a/lazy-lock.json +++ b/lazy-lock.json @@ -8,20 +8,22 @@ "cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" }, "context.vim": { "branch": "master", "commit": "82eb26de265292808917b82f3eda2725b53d785c" }, "fidget.nvim": { "branch": "main", "commit": "e2a175c2abe2d4f65357da1c98c59a5cfb2b543f" }, - "harpoon": { "branch": "harpoon2", "commit": "0378a6c428a0bed6a2781d459d7943843f374bce" }, + "harpoon": { "branch": "harpoon2", "commit": "a84ab829eaf3678b586609888ef52f7779102263" }, "lazy.nvim": { "branch": "main", "commit": "7967abe55752aa90532e6bb4bd4663fe27a264cb" }, "mason-lspconfig.nvim": { "branch": "main", "commit": "4d0e5b49363cac187326998b96aa6a2884e0e89b" }, "mason.nvim": { "branch": "main", "commit": "e2f7f9044ec30067bc11800a9e266664b88cda22" }, "neo-tree.nvim": { "branch": "v3.x", "commit": "a77af2e764c5ed4038d27d1c463fa49cd4794e07" }, "nui.nvim": { "branch": "main", "commit": "b58e2bfda5cea347c9d58b7f11cf3012c7b3953f" }, "nvim": { "branch": "main", "commit": "637d99e638bc6f1efedac582f6ccab08badac0c6" }, + "nvim-autopairs": { "branch": "master", "commit": "ee297f215e95a60b01fde33275cc3c820eddeebe" }, "nvim-cmp": { "branch": "main", "commit": "f17d9b4394027ff4442b298398dfcaab97e40c4f" }, "nvim-lspconfig": { "branch": "master", "commit": "d2d153a179ed59aa7134d7ebdf4d7dcb156efa22" }, - "nvim-treesitter": { "branch": "master", "commit": "7646c1c12a3121562aa87fd79aace48c728ac096" }, + "nvim-treesitter": { "branch": "master", "commit": "e1e3108cd23d7f967842261bd66126b6734d8907" }, "nvim-web-devicons": { "branch": "master", "commit": "19d257cf889f79f4022163c3fbb5e08639077bd8" }, "plenary.nvim": { "branch": "master", "commit": "2d9b06177a975543726ce5c73fca176cedbffe9d" }, "telescope.nvim": { "branch": "master", "commit": "a0bbec21143c7bc5f8bb02e0005fa0b982edc026" }, "undotree": { "branch": "master", "commit": "78b5241191852ffa9bb5da5ff2ee033160798c3b" }, "vim-fugitive": { "branch": "master", "commit": "d4877e54cef67f5af4f950935b1ade19ed6b7370" }, - "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" } + "vim-surround": { "branch": "master", "commit": "3d188ed2113431cf8dac77be61b842acb64433d9" }, + "vim-visual-multi": { "branch": "master", "commit": "a6975e7c1ee157615bbc80fc25e4392f71c344d4" } } diff --git a/lua/plugins/autopairs.lua b/lua/plugins/autopairs.lua new file mode 100644 index 0000000..2db00d8 --- /dev/null +++ b/lua/plugins/autopairs.lua @@ -0,0 +1,7 @@ +return { + 'windwp/nvim-autopairs', + event = "InsertEnter", + config = true + -- use opts = {} for passing setup options + -- this is equivalent to setup({}) function +} diff --git a/lua/plugins/lspzero.lua b/lua/plugins/lspzero.lua index a894526..bb131bc 100644 --- a/lua/plugins/lspzero.lua +++ b/lua/plugins/lspzero.lua @@ -1,120 +1,136 @@ return { - { - 'williamboman/mason.nvim', - lazy = false, - opts = {}, - }, - - -- Autocompletion - { - 'hrsh7th/nvim-cmp', - event = 'InsertEnter', - config = function() - local cmp = require('cmp') + { + 'williamboman/mason.nvim', + lazy = false, + opts = {}, + }, - cmp.setup({ - sources = { - { name = 'nvim_lsp' }, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.complete(), - [''] = cmp.mapping.scroll_docs(-4), - [''] = cmp.mapping.scroll_docs(4), - }), - snippet = { - expand = function(args) - vim.snippet.expand(args.body) - end, - }, - }) - end - }, + -- Autocompletion + { + 'hrsh7th/nvim-cmp', + event = 'InsertEnter', + config = function() + local cmp = require('cmp') - -- LSP - { - 'neovim/nvim-lspconfig', - cmd = { 'LspInfo', 'LspInstall', 'LspStart' }, - event = { 'BufReadPre', 'BufNewFile' }, - dependencies = { - "williamboman/mason.nvim", - "williamboman/mason-lspconfig.nvim", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-cmdline", - "hrsh7th/nvim-cmp", - "L3MON4D3/LuaSnip", - "saadparwaiz1/cmp_luasnip", - "j-hui/fidget.nvim", + cmp.setup({ + sources = { + { name = 'nvim_lsp' }, }, - init = function() - -- Reserve a space in the gutter - -- This will avoid an annoying layout shift in the screen - vim.opt.signcolumn = 'yes' - end, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.complete(), + [''] = cmp.mapping.scroll_docs(-4), + [''] = cmp.mapping.scroll_docs(4), + }), + snippet = { + expand = function(args) + vim.snippet.expand(args.body) + end, + }, + }) + end + }, + + -- LSP + { + 'neovim/nvim-lspconfig', + cmd = { 'LspInfo', 'LspInstall', 'LspStart' }, + event = { 'BufReadPre', 'BufNewFile' }, + dependencies = { + "williamboman/mason.nvim", + "williamboman/mason-lspconfig.nvim", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-cmdline", + "hrsh7th/nvim-cmp", + "L3MON4D3/LuaSnip", + "saadparwaiz1/cmp_luasnip", + "j-hui/fidget.nvim", + }, + init = function() + -- Reserve a space in the gutter + -- This will avoid an annoying layout shift in the screen + vim.opt.signcolumn = 'yes' + end, - config = function() - local lsp_defaults = require('lspconfig').util.default_config + config = function() + local lsp_defaults = require('lspconfig').util.default_config - require('mason-lspconfig').setup({ - ensure_installed = { "eslint" }, - handlers = { - -- this first function is the "default handler" - -- it applies to every language server without a "custom handler" - function(server_name) - require('lspconfig')[server_name].setup({}) - end, - } - }) + require('mason-lspconfig').setup({ + ensure_installed = { "eslint" }, + handlers = { + -- this first function is the "default handler" + -- it applies to every language server without a "custom handler" + function(server_name) + require('lspconfig')[server_name].setup({}) + end, + } + }) - -- Add cmp_nvim_lsp capabilities settings to lspconfig - -- This should be executed before you configure any language server - lsp_defaults.capabilities = vim.tbl_deep_extend( - 'force', - lsp_defaults.capabilities, - require('cmp_nvim_lsp').default_capabilities() - ) + -- Add cmp_nvim_lsp capabilities settings to lspconfig + -- This should be executed before you configure any language server + lsp_defaults.capabilities = vim.tbl_deep_extend( + 'force', + lsp_defaults.capabilities, + require('cmp_nvim_lsp').default_capabilities() + ) - -- LspAttach is where you enable features that only work - -- if there is a language server active in the file - vim.api.nvim_create_autocmd('LspAttach', { - desc = 'LSP actions', - callback = function(event) - local opts = { buffer = event.buf } + -- LspAttach is where you enable features that only work + -- if there is a language server active in the file + vim.api.nvim_create_autocmd('LspAttach', { + desc = 'LSP actions', + callback = function(event) + local opts = { buffer = event.buf } - vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) - vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) - vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) - vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) - vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) - vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) - vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) - vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) - vim.keymap.set({ 'n', 'x' }, '', 'lua vim.lsp.buf.format({async = true})', opts) - vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) - end, - }) + vim.keymap.set('n', 'K', 'lua vim.lsp.buf.hover()', opts) + vim.keymap.set('n', 'gd', 'lua vim.lsp.buf.definition()', opts) + vim.keymap.set('n', 'gD', 'lua vim.lsp.buf.declaration()', opts) + vim.keymap.set('n', 'gi', 'lua vim.lsp.buf.implementation()', opts) + vim.keymap.set('n', 'go', 'lua vim.lsp.buf.type_definition()', opts) + vim.keymap.set('n', 'gr', 'lua vim.lsp.buf.references()', opts) + vim.keymap.set('n', 'gs', 'lua vim.lsp.buf.signature_help()', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.rename()', opts) + vim.keymap.set({ 'n', 'x' }, '', 'lua vim.lsp.buf.format({async = true})', opts) + vim.keymap.set('n', '', 'lua vim.lsp.buf.code_action()', opts) + end, - local cmp = require('cmp') - local cmp_select = { behaviour = cmp.SelectBehavior.Select } + }) - cmp.setup({ - sources = { - { name = 'nvim_lsp' }, - { name = 'luasnip' }, - }, - snippet = { - expand = function(args) - require('luasnip').lsp_expand(args.body) - end, - }, - mapping = cmp.mapping.preset.insert({ - [''] = cmp.mapping.select_prev_item(cmp_select), - [''] = cmp.mapping.select_next_item(cmp_select), - [''] = cmp.mapping.confirm({ select = true }), - [''] = cmp.mapping.complete(), - }), - }) + vim.api.nvim_create_autocmd("CursorHold", { + buffer = bufnr, + callback = function() + local opts = { + focusable = false, + close_events = { "BufLeave", "CursorMoved", "InsertEnter", "FocusLost" }, + border = 'rounded', + source = 'always', + prefix = ' ', + scope = 'cursor', + } + vim.diagnostic.open_float(nil, opts) end - }, + }) + + local cmp = require('cmp') + local cmp_select = { behaviour = cmp.SelectBehavior.Select } + + cmp.setup({ + sources = { + { name = 'nvim_lsp' }, + { name = 'luasnip' }, + }, + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + mapping = cmp.mapping.preset.insert({ + [''] = cmp.mapping.select_prev_item(cmp_select), + [''] = cmp.mapping.select_next_item(cmp_select), + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping.complete(), + }), + }) + end + }, } diff --git a/lua/plugins/visual-multi.lua b/lua/plugins/visual-multi.lua new file mode 100644 index 0000000..4868274 --- /dev/null +++ b/lua/plugins/visual-multi.lua @@ -0,0 +1,3 @@ +return { + "mg979/vim-visual-multi" +}