From 73283b58b492bbdf0118c1e5e73613964e107473 Mon Sep 17 00:00:00 2001 From: Patrick Auernig Date: Thu, 4 May 2023 21:58:15 +0200 Subject: [PATCH] Add undotree plugin and update lsp config --- after/plugin/lsp.lua | 28 ++++++++++++++++++------ after/plugin/undotree.lua | 3 +++ lua/valeth/init.lua | 9 ++++++++ lua/valeth/packer.lua | 45 +++++++++++++++++++++++++++++---------- 4 files changed, 67 insertions(+), 18 deletions(-) create mode 100644 after/plugin/undotree.lua diff --git a/after/plugin/lsp.lua b/after/plugin/lsp.lua index 6784062..75e013e 100644 --- a/after/plugin/lsp.lua +++ b/after/plugin/lsp.lua @@ -10,23 +10,38 @@ lsp.nvim_workspace() local cmp = require("cmp") local cmp_select = { behavior = cmp.SelectBehavior.Select } - -lsp.setup_nvim_cmp({ - mapping = lsp.defaults.cmp_mappings({ +local cmp_mapping = lsp.defaults.cmp_mappings({ [""] = cmp.mapping.select_prev_item(cmp_select), [""] = cmp.mapping.select_next_item(cmp_select), + [""] = cmp.mapping.confirm({ select = true }), [""] = cmp.mapping.complete(), - }) }) -lsp.on_attach(function(client, buffnr) - lsp.default_keymaps({ buffer = buffnr }) +lsp.setup_nvim_cmp({ mapping = cmp_mapping }) + +-- Gimme pretty icons +lsp.set_sign_icons({ + error = '✘', + warn = '▲', + hint = '⚑', + info = '»' +}) + +lsp.on_attach(function(_, buffnr) + local opts = { buffer = buffnr, remap = false } + + vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts) + vim.keymap.set("n", "gr", vim.lsp.buf.references, opts) + vim.keymap.set("n", "K", vim.lsp.buf.hover, opts) + vim.keymap.set("n", "re", vim.lsp.buf.rename, opts) + vim.keymap.set({"n", "i"}, "", vim.lsp.buf.signature_help, opts) vim.keymap.set("n", "fmt", function() vim.lsp.buf.format({ async = false, timeout_ms = 5000 }) end) end) + -- NOTE: Format on save does not support async formatting lsp.format_on_save({ servers = { @@ -34,5 +49,4 @@ lsp.format_on_save({ } }) - lsp.setup() diff --git a/after/plugin/undotree.lua b/after/plugin/undotree.lua new file mode 100644 index 0000000..7961a75 --- /dev/null +++ b/after/plugin/undotree.lua @@ -0,0 +1,3 @@ +local undotree = require("undotree") + +vim.keymap.set("n", "u", undotree.toggle, { noremap = true, silent = true }) diff --git a/lua/valeth/init.lua b/lua/valeth/init.lua index 195a029..e933b8d 100644 --- a/lua/valeth/init.lua +++ b/lua/valeth/init.lua @@ -23,3 +23,12 @@ vim.keymap.set({"n", "v", "i"}, "", "w") vim.keymap.set({"n", "v"}, "", "") vim.keymap.set("n", "s", "") + +-- Some nice remaps (thanks Prime) + +-- Move selected lines up or down +vim.keymap.set("v", "J", ":move '>+1gv=gv") +vim.keymap.set("v", "K", ":move '<-2gv=gv") + +-- Join lines without moving the cursor +vim.keymap.set("n", "J", "mzJ`z") diff --git a/lua/valeth/packer.lua b/lua/valeth/packer.lua index 214b758..8ad9105 100644 --- a/lua/valeth/packer.lua +++ b/lua/valeth/packer.lua @@ -17,12 +17,15 @@ return require("packer").startup(function(use) "VonHeikemen/lsp-zero.nvim", branch = "v2.x", requires = { - {"neovim/nvim-lspconfig"}, - {"hrsh7th/nvim-cmp"}, - {"hrsh7th/cmp-nvim-lsp"}, - {"hrsh7th/cmp-path"}, - {"williamboman/mason.nvim"}, - {"williamboman/mason-lspconfig.nvim"}, + { "neovim/nvim-lspconfig" }, + { "hrsh7th/nvim-cmp" }, + { "hrsh7th/cmp-nvim-lsp" }, + { "hrsh7th/cmp-path" }, + { "saadparwaiz1/cmp_luasnip" }, + { "L3MON4D3/LuaSnip" }, + { "rafamadriz/friendly-snippets" }, + { "williamboman/mason.nvim" }, + { "williamboman/mason-lspconfig.nvim" }, } } @@ -34,7 +37,7 @@ return require("packer").startup(function(use) use { "CantoroMC/ayu-nvim", config = function() - vim.cmd("colorscheme ayu") + vim.cmd.colorscheme("ayu") end } @@ -59,8 +62,19 @@ return require("packer").startup(function(use) use { "windwp/nvim-autopairs", + requires = { + { "hrsh7th/nvim-cmp" }, + }, config = function() - require("nvim-autopairs").setup() + local ap = require("nvim-autopairs") + local ap_cmp = require("nvim-autopairs.completion.cmp") + local cmp = require("cmp") + + cmp.event:on("confirm_done", ap_cmp.on_confirm_done()) + + ap.setup { + check_ts = true + } end } @@ -71,8 +85,8 @@ return require("packer").startup(function(use) "nvim-telescope/telescope.nvim", tag = "0.1.1", requires = { - {"nvim-lua/plenary.nvim"}, - {"nvim-treesitter/nvim-treesitter"}, + { "nvim-lua/plenary.nvim" }, + { "nvim-treesitter/nvim-treesitter" }, }, config = function() require("telescope").load_extension("harpoon") @@ -82,8 +96,17 @@ return require("packer").startup(function(use) use { "ThePrimeagen/harpoon", requires = { - {"nvim-lua/plenary.nvim"}, + { "nvim-lua/plenary.nvim" }, } } + use { + "jiaoshijie/undotree", + requires = { + "nvim-lua/plenary.nvim" + }, + config = function() + require("undotree").setup() + end + } end)