From 3d3380b6b6c658eff8c53323a3a00688beeab7bc Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Tue, 22 Aug 2023 16:51:35 +0200 Subject: [PATCH] Improved neovim config --- .config/nvim/lazy-lock.json | 10 ++-- .config/nvim/lua/config/autocmds.lua | 3 +- .config/nvim/lua/config/keys.lua | 23 ++++---- .config/nvim/lua/config/settings.lua | 8 ++- .config/nvim/lua/plugins/cmp.lua | 79 +++++++++++++++++++++++++- .config/nvim/lua/plugins/telescope.lua | 1 + .config/nvim/lua/plugins/theme.lua | 4 ++ .config/nvim/lua/plugins/tree.lua | 3 + .config/nvim/lua/plugins/trouble.lua | 18 ++++++ 9 files changed, 129 insertions(+), 20 deletions(-) create mode 100644 .config/nvim/lua/plugins/trouble.lua diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index a59b2c8..84384ac 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -1,24 +1,26 @@ { "Comment.nvim": { "branch": "master", "commit": "0236521ea582747b58869cb72f70ccfa967d2e89" }, + "LuaSnip": { "branch": "master", "commit": "c4d6298347f7707e9757351b2ee03d0c00da5c20" }, "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, "flash.nvim": { "branch": "main", "commit": "967117690bd677cb7b6a87f0bc0077d2c0be3a27" }, "gitsigns.nvim": { "branch": "main", "commit": "749267aaa863c30d721c9913699c5d94e0c07dd3" }, "lazy.nvim": { "branch": "main", "commit": "dac844ed617dda4f9ec85eb88e9629ad2add5e05" }, - "neodev.nvim": { "branch": "main", "commit": "e9bc652e22f9cd1892630bf019db363ac403ee39" }, + "neodev.nvim": { "branch": "main", "commit": "02d5988929635fe913daa60f19b909e6a7b23c58" }, "noice.nvim": { "branch": "main", "commit": "894db25ec726d32047799d4d0a982b701bec453b" }, "nui.nvim": { "branch": "main", "commit": "9e3916e784660f55f47daa6f26053ad044db5d6a" }, "nvim-cmp": { "branch": "main", "commit": "51f1e11a89ec701221877532ee1a23557d291dd5" }, - "nvim-lspconfig": { "branch": "master", "commit": "67f151e84daddc86cc65f5d935e592f76b9f4496" }, + "nvim-lspconfig": { "branch": "master", "commit": "93c6826b16217eaef568ca5c224ea5d0c12bbb82" }, "nvim-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" }, "nvim-spectre": { "branch": "master", "commit": "eb17a856a6f17e03d8d610cbc00cd9f2f39e3fd7" }, "nvim-tree.lua": { "branch": "master", "commit": "920868dba13466586897a8f40220eca6b2caac41" }, - "nvim-treesitter": { "branch": "master", "commit": "7c935d6bd5ecb36e7c6cf6678e1eaa38b85111f3" }, + "nvim-treesitter": { "branch": "master", "commit": "2ee71c1a2fa74c10692be10ae420ff0c3a02eb3c" }, "nvim-web-devicons": { "branch": "master", "commit": "cfc8824cc1db316a276b36517f093baccb8e799a" }, "nvterm": { "branch": "main", "commit": "5ae78fb332e92447121d2af58a6313189a7799fb" }, "onedark.nvim": { "branch": "master", "commit": "09b71d84bd2524438e48c0aa5b54d855cc72af32" }, "plenary.nvim": { "branch": "master", "commit": "267282a9ce242bbb0c5dc31445b6d353bed978bb" }, "telescope-project.nvim": { "branch": "master", "commit": "7c64b181dd4e72deddcf6f319e3bf1e95b2a2f30" }, - "telescope.nvim": { "branch": "master", "commit": "2d92125620417fbea82ec30303823e3cd69e90e8" } + "telescope.nvim": { "branch": "master", "commit": "2d92125620417fbea82ec30303823e3cd69e90e8" }, + "trouble.nvim": { "branch": "main", "commit": "40aad004f53ae1d1ba91bcc5c29d59f07c5f01d3" } } \ No newline at end of file diff --git a/.config/nvim/lua/config/autocmds.lua b/.config/nvim/lua/config/autocmds.lua index 657191b..0466de8 100644 --- a/.config/nvim/lua/config/autocmds.lua +++ b/.config/nvim/lua/config/autocmds.lua @@ -15,6 +15,7 @@ on({ "TermOpen", "TermEnter" }, { on({ "BufNewFile", "BufRead" }, { pattern = { "*.txt", "*.md" }, callback = function() - vim.lo.wrap = true + vim.opt_local.wrap = true + vim.opt_local.signcolumn = "no" end, }) diff --git a/.config/nvim/lua/config/keys.lua b/.config/nvim/lua/config/keys.lua index fb7a931..c7d4c51 100644 --- a/.config/nvim/lua/config/keys.lua +++ b/.config/nvim/lua/config/keys.lua @@ -1,28 +1,31 @@ -local map = function(mode, lhs, rhs, info) +local function map(mode, lhs, rhs, info) vim.keymap.set(mode, lhs, rhs, { desc = info }) end -- Basics map("n", ";", ":", "Command mode") +map("n", "qq", "qa!", "Quit all") +map("n", "U", "redo", "Redo") map({ "i", "n" }, "", "noh", "Clear search") map({ "i", "n", "s", "v" }, "", "w", "Save file") -map("n", "U", "redo", "Redo") +map("n", "", "bd", "Delete buffer") map("n", "", "enew", "New File") +map("n", "", "^Da", "Rewrite line") +map("i", "", "^Da", "Rewrite line") map("n", "", ":%s///g", "Replace word under cursor") -map("n", "", "qa", "Quit all") -map({"n", "v"}, "", "^", "Beginning of line") +map({ "n", "v" }, "", "^", "Beginning of line") map("i", "", "^i", "Beginning of line") -map({"i", "n", "v"}, "", "", "End of line") +map({ "i", "n", "v" }, "", "", "End of line") -- Indenting map("v", "<", "", ">gv") -- LSP -map("n", "gd", vim.lsp.buf.definition, "Go to definition") -map("n", "gr", vim.lsp.buf.references, "Go to references") -map("n", "cf", vim.lsp.buf.format, "Format") +map("n", "gr", vim.lsp.buf.references, "Get references") +map("n", "gd", vim.lsp.buf.definition, "Get definition") +map({ "n", "i" }, "", vim.lsp.buf.hover, "Show information") +map({ "n", "i" }, "", vim.lsp.buf.format, "Format") --- Plugins -map("n", "t", "NvimTreeToggle", "Toggle tree") +-- Package manager map("n", "l", "Lazy", "Lazy") diff --git a/.config/nvim/lua/config/settings.lua b/.config/nvim/lua/config/settings.lua index 6c591c1..f944711 100644 --- a/.config/nvim/lua/config/settings.lua +++ b/.config/nvim/lua/config/settings.lua @@ -16,15 +16,15 @@ opt.cursorline = true opt.cursorlineopt = "both" opt.expandtab = false opt.grepformat = "%f:%l:%c:%m" -opt.grepprg = "rg --vimgrep" +opt.grepprg = "rg --grep" opt.ignorecase = false -opt.laststatus = 0 opt.mouse = "a" opt.ruler = false opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } opt.shiftwidth = 4 -opt.shortmess:append "sI" +opt.shortmess:append "sCFI" opt.showmode = false +opt.showtabline = 0 opt.smartindent = true opt.softtabstop = 4 opt.spell = false @@ -40,6 +40,8 @@ opt.wrap = false -- UI opt.fillchars = { eob = " ", vert = " " } +opt.laststatus = 0 opt.number = true opt.relativenumber = false opt.signcolumn = "yes:1" +opt.statusline = "%{repeat('─',winwidth('.'))}" diff --git a/.config/nvim/lua/plugins/cmp.lua b/.config/nvim/lua/plugins/cmp.lua index 2f8038d..9d72bf7 100644 --- a/.config/nvim/lua/plugins/cmp.lua +++ b/.config/nvim/lua/plugins/cmp.lua @@ -1,3 +1,46 @@ +local icons = { + Namespace = "󰌗", + Text = "󰉿", + Method = "󰆧", + Function = "󰆧", + Constructor = "", + Field = "󰜢", + Variable = "󰀫", + Class = "󰠱", + Interface = "", + Module = "", + Property = "󰜢", + Unit = "󰑭", + Value = "󰎠", + Enum = "", + Keyword = "󰌋", + Snippet = "", + Color = "󰏘", + File = "󰈚", + Reference = "󰈇", + Folder = "󰉋", + EnumMember = "", + Constant = "󰏿", + Struct = "󰙅", + Event = "", + Operator = "󰆕", + TypeParameter = "󰊄", + Table = "", + Object = "󰅩", + Tag = "", + Array = "[]", + Boolean = "", + Number = "", + Null = "󰟢", + String = "󰉿", + Calendar = "", + Watch = "󰥔", + Package = "", + Copilot = "", + Codeium = "", + TabNine = "", +} + return { "hrsh7th/nvim-cmp", event = "InsertEnter", @@ -5,20 +48,52 @@ return { "hrsh7th/cmp-nvim-lsp", "hrsh7th/cmp-buffer", "hrsh7th/cmp-path", + "L3MON4D3/LuaSnip", }, config = function() local cmp = require("cmp") - cmp.setup({ + local opts = { + completion = { + completeopt = "menu,menuone,noinsert", + }, + formatting = { + fields = { "abbr", "kind", "menu" }, + format = function(_, item) + local icon = icons[item.kind] or "" + item.kind = string.format(" %s %s", icon, item.kind) + return item + end, + }, mapping = { [""] = cmp.mapping.complete(), + [""] = cmp.mapping.select_prev_item(), + [""] = cmp.mapping.select_next_item(), + [""] = cmp.mapping.abort(), [""] = cmp.mapping.confirm({ select = true }), }, + snippet = { + expand = function(args) + require("luasnip").lsp_expand(args.body) + end, + }, sources = { { name = "nvim_lsp" }, + { name = "luasnip" }, { name = "buffer" }, { name = "path" }, }, - }) + window = { + completion = { + border = "rounded", + scrollbar = false + }, + documentation = { + border = "rounded", + } + }, + } + + cmp.setup(opts) end, } diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index 8da526e..681eaf1 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -8,6 +8,7 @@ return { {"f", "Telescope find_files", desc = "Find files"}, {"r", "Telescope oldfiles", desc = "Recent files"}, {"p", "Telescope project", desc = "Projects"}, + {"b", "Telescope buffers", desc = "Buffers"}, }, config = function() require("telescope").setup({ diff --git a/.config/nvim/lua/plugins/theme.lua b/.config/nvim/lua/plugins/theme.lua index 7d5679b..451b70a 100644 --- a/.config/nvim/lua/plugins/theme.lua +++ b/.config/nvim/lua/plugins/theme.lua @@ -6,6 +6,10 @@ return { style = "dark", transparent = false, term_colors = true, + highlights = { + ["StatusLine"] = {fg = "$bg3", bg = "Normal"}, + ["StatusLineNC"] = {fg = "$bg3", bg = "Normal"}, + }, }, config = function(_, opts) local theme = require("onedark") diff --git a/.config/nvim/lua/plugins/tree.lua b/.config/nvim/lua/plugins/tree.lua index ed30fb0..c3dcf3c 100644 --- a/.config/nvim/lua/plugins/tree.lua +++ b/.config/nvim/lua/plugins/tree.lua @@ -4,6 +4,9 @@ return { dependencies = { "nvim-tree/nvim-web-devicons", }, + keys = { + { "e", function() require("nvim-tree.api").tree.toggle() end, desc = "Toggle files" }, + }, opts = { filesystem_watchers = { enable = true, diff --git a/.config/nvim/lua/plugins/trouble.lua b/.config/nvim/lua/plugins/trouble.lua new file mode 100644 index 0000000..749f610 --- /dev/null +++ b/.config/nvim/lua/plugins/trouble.lua @@ -0,0 +1,18 @@ +return { + "folke/trouble.nvim", + event = "VeryLazy", + keys = { + { "x", function() require("trouble").toggle() end, desc = "Show errors" }, + }, + dependencies = { + "nvim-tree/nvim-web-devicons", + }, + opts = { + position = "right", + padding = false, + use_diagnostic_signs = true, + auto_open = true, + auto_close = true, + }, + config = true, +}