From ce110d730e43eab3fbfdb6011704326463630333 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Mon, 21 Aug 2023 19:19:37 +0200 Subject: [PATCH] Improved neovim config --- .config/nvim/init.lua | 2 +- .config/nvim/lazy-lock.json | 6 +- .config/nvim/lua/boot.lua | 31 +++++++-- .config/nvim/lua/config/keys.lua | 23 ++++--- .config/nvim/lua/config/settings.lua | 18 +++-- .config/nvim/lua/plugins/comment.lua | 5 +- .config/nvim/lua/plugins/flash.lua | 7 ++ .config/nvim/lua/plugins/lsp.lua | 65 +++++++++++++------ .config/nvim/lua/plugins/nvterm.lua | 7 ++ .config/nvim/lua/plugins/spectre.lua | 7 ++ .../nvim/lua/plugins/telescope-browser.lua | 13 ---- .config/nvim/lua/plugins/telescope.lua | 25 ++++++- .config/nvim/lua/plugins/term.lua | 5 -- .config/nvim/lua/plugins/theme.lua | 1 + .config/nvim/lua/plugins/tree.lua | 30 ++++++--- 15 files changed, 169 insertions(+), 76 deletions(-) create mode 100644 .config/nvim/lua/plugins/flash.lua create mode 100644 .config/nvim/lua/plugins/nvterm.lua create mode 100644 .config/nvim/lua/plugins/spectre.lua delete mode 100644 .config/nvim/lua/plugins/telescope-browser.lua delete mode 100644 .config/nvim/lua/plugins/term.lua diff --git a/.config/nvim/init.lua b/.config/nvim/init.lua index 9197cdb..9722fe2 100644 --- a/.config/nvim/init.lua +++ b/.config/nvim/init.lua @@ -1,4 +1,4 @@ require("config.settings") -require("config.keys") require("boot") +require("config.keys") require("config.autocmds") diff --git a/.config/nvim/lazy-lock.json b/.config/nvim/lazy-lock.json index 13ac09c..a59b2c8 100644 --- a/.config/nvim/lazy-lock.json +++ b/.config/nvim/lazy-lock.json @@ -3,18 +3,22 @@ "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" }, "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-notify": { "branch": "master", "commit": "ea9c8ce7a37f2238f934e087c255758659948e0f" }, + "nvim-spectre": { "branch": "master", "commit": "eb17a856a6f17e03d8d610cbc00cd9f2f39e3fd7" }, "nvim-tree.lua": { "branch": "master", "commit": "920868dba13466586897a8f40220eca6b2caac41" }, - "nvim-treesitter": { "branch": "master", "commit": "a185f8ebae9006b181e83f6569df68e7ff8aeb80" }, + "nvim-treesitter": { "branch": "master", "commit": "7c935d6bd5ecb36e7c6cf6678e1eaa38b85111f3" }, "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" } } \ No newline at end of file diff --git a/.config/nvim/lua/boot.lua b/.config/nvim/lua/boot.lua index a9a39a5..6e71113 100644 --- a/.config/nvim/lua/boot.lua +++ b/.config/nvim/lua/boot.lua @@ -1,4 +1,3 @@ --- Bootstrap lazy.nvim local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" if not vim.loop.fs_stat(lazypath) then vim.fn.system({ @@ -12,7 +11,6 @@ if not vim.loop.fs_stat(lazypath) then end vim.opt.rtp:prepend(lazypath) --- Setup package manager require("lazy").setup("plugins", { defaults = { lazy = true, @@ -23,12 +21,33 @@ require("lazy").setup("plugins", { performance = { rtp = { disabled_plugins = { - "gzip", - "netrwPlugin", - "tarPlugin", + "2html_plugin", "tohtml", - "tutor", + "getscript", + "getscriptPlugin", + "gzip", + "logipat", + "netrw", + "netrwPlugin", + "netrwSettings", + "netrwFileHandlers", + "matchit", + "tar", + "tarPlugin", + "rrhelper", + "spellfile_plugin", + "vimball", + "vimballPlugin", + "zip", "zipPlugin", + "tutor", + "rplugin", + "syntax", + "synmenu", + "optwin", + "compiler", + "bugreport", + "ftplugin", }, }, }, diff --git a/.config/nvim/lua/config/keys.lua b/.config/nvim/lua/config/keys.lua index 56ef219..fb7a931 100644 --- a/.config/nvim/lua/config/keys.lua +++ b/.config/nvim/lua/config/keys.lua @@ -3,10 +3,16 @@ local map = function(mode, lhs, rhs, info) end -- Basics -map("n", "", "enew", "New File") -map({ "i", "n", "s", "v" }, "", "w", "Save file") -map("n", "", "qa", "Quit all") +map("n", ";", ":", "Command mode") map({ "i", "n" }, "", "noh", "Clear search") +map({ "i", "n", "s", "v" }, "", "w", "Save file") +map("n", "U", "redo", "Redo") +map("n", "", "enew", "New File") +map("n", "", ":%s///g", "Replace word under cursor") +map("n", "", "qa", "Quit all") +map({"n", "v"}, "", "^", "Beginning of line") +map("i", "", "^i", "Beginning of line") +map({"i", "n", "v"}, "", "", "End of line") -- Indenting map("v", "<", "cf", vim.lsp.buf.format, "Format") --- Toggle comment -map("n", "", "lua require('Comment.api').toggle.linewise.current()", "Toggle comment") -map("v", "", "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", "Toggle comment") - --- Normal mode -map("n", "", "NvimTreeToggle", "Toggle tree") +-- Plugins +map("n", "t", "NvimTreeToggle", "Toggle tree") map("n", "l", "Lazy", "Lazy") -map("n", "f", "Telescope find_files", "Find files") -map("n", "r", "Telescope oldfiles", "Recent files") -map({ "n", "t" }, "", "lua require('nvterm.terminal').toggle('float')", "Toggle terminal") diff --git a/.config/nvim/lua/config/settings.lua b/.config/nvim/lua/config/settings.lua index ade72f8..6c591c1 100644 --- a/.config/nvim/lua/config/settings.lua +++ b/.config/nvim/lua/config/settings.lua @@ -1,8 +1,12 @@ +-- Globals local g = vim.g g.mapleader = " " -g.loaded_netrw = 1 -g.loaded_netrwPlugin = 1 +for _, provider in ipairs { "node", "perl", "python3", "ruby" } do + g["loaded_" .. provider .. "_provider"] = 0 +end + +-- Options local opt = vim.opt opt.autoindent = true opt.autowrite = false @@ -16,13 +20,11 @@ opt.grepprg = "rg --vimgrep" opt.ignorecase = false opt.laststatus = 0 opt.mouse = "a" -opt.number = true -opt.relativenumber = false opt.ruler = false opt.sessionoptions = { "buffers", "curdir", "tabpages", "winsize" } opt.shiftwidth = 4 +opt.shortmess:append "sI" opt.showmode = false -opt.signcolumn = "yes" opt.smartindent = true opt.softtabstop = 4 opt.spell = false @@ -35,3 +37,9 @@ opt.undolevels = 10000 opt.updatetime = 250 opt.wildmode = "longest:full,full" opt.wrap = false + +-- UI +opt.fillchars = { eob = " ", vert = " " } +opt.number = true +opt.relativenumber = false +opt.signcolumn = "yes:1" diff --git a/.config/nvim/lua/plugins/comment.lua b/.config/nvim/lua/plugins/comment.lua index 27463d8..4c66ce9 100644 --- a/.config/nvim/lua/plugins/comment.lua +++ b/.config/nvim/lua/plugins/comment.lua @@ -1,6 +1,9 @@ return { "numToStr/Comment.nvim", - event = "VeryLazy", + keys = { + {"", "lua require('Comment.api').toggle.linewise.current()", desc = "Toggle comment"}, + {"", "lua require('Comment.api').toggle.linewise(vim.fn.visualmode())", mode = "v", desc = "Toggle comment"}, + }, config = true, opts = { mappings = { diff --git a/.config/nvim/lua/plugins/flash.lua b/.config/nvim/lua/plugins/flash.lua new file mode 100644 index 0000000..02677fa --- /dev/null +++ b/.config/nvim/lua/plugins/flash.lua @@ -0,0 +1,7 @@ +return { + "folke/flash.nvim", + keys = { + { "s", function() require("flash").jump() end, mode = { "n", "x", "o" }, desc = "Flash" }, + { "S", function() require("flash").treesitter() end, mode = { "n", "o", "x" }, desc = "Flash Treesitter" }, + }, +} diff --git a/.config/nvim/lua/plugins/lsp.lua b/.config/nvim/lua/plugins/lsp.lua index d099721..0a75b6b 100644 --- a/.config/nvim/lua/plugins/lsp.lua +++ b/.config/nvim/lua/plugins/lsp.lua @@ -1,24 +1,49 @@ return { - "neovim/nvim-lspconfig", - event = { "BufReadPre", "BufNewFile" }, - opts = { - servers = { - lua_ls = {}, - gopls = {}, - - -- web dev - --cssls = {}, - --html = {}, - --jsonls = {}, - --tsserver = {}, - --svelte = {}, + "neovim/nvim-lspconfig", + event = { "BufReadPre", "BufNewFile" }, + dependencies = { + "folke/neodev.nvim", + }, + opts = { + servers = { + gopls = {}, + lua_ls = { + settings = { + Lua = { + workspace = { + checkThirdParty = false, + }, + }, + }, }, + --cssls = {}, + --html = {}, + --jsonls = {}, + --tsserver = {}, + --svelte = {}, }, - config = function(_, opts) - local servers = opts.servers + }, + config = function(_, opts) + require("neodev").setup() - for server, server_opts in pairs(servers) do - require("lspconfig")[server].setup(server_opts) - end - end, - } + -- Servers + local servers = opts.servers + + for server, server_opts in pairs(servers) do + require("lspconfig")[server].setup(server_opts) + end + + -- Icons + local icons = { + Error = " ", + Warn = " ", + Hint = " ", + Info = " ", + } + + for name, icon in pairs(icons) do + name = "DiagnosticSign" .. name + vim.fn.sign_define(name, { text = icon, texthl = name, numhl = "" }) + end + end, +} diff --git a/.config/nvim/lua/plugins/nvterm.lua b/.config/nvim/lua/plugins/nvterm.lua new file mode 100644 index 0000000..ae6851d --- /dev/null +++ b/.config/nvim/lua/plugins/nvterm.lua @@ -0,0 +1,7 @@ +return { + "NvChad/nvterm", + keys = { + { "", "lua require('nvterm.terminal').toggle('float')", mode = { "n", "t" }, desc = "Toggle terminal" }, + }, + config = true, +} diff --git a/.config/nvim/lua/plugins/spectre.lua b/.config/nvim/lua/plugins/spectre.lua new file mode 100644 index 0000000..ebbe15e --- /dev/null +++ b/.config/nvim/lua/plugins/spectre.lua @@ -0,0 +1,7 @@ +return { + "nvim-pack/nvim-spectre", + keys = { + { "sr", function() require("spectre").open() end, desc = "Replace in files (Spectre)" }, + }, + config = true, +} diff --git a/.config/nvim/lua/plugins/telescope-browser.lua b/.config/nvim/lua/plugins/telescope-browser.lua deleted file mode 100644 index 82ea57c..0000000 --- a/.config/nvim/lua/plugins/telescope-browser.lua +++ /dev/null @@ -1,13 +0,0 @@ -return { - "nvim-telescope/telescope-file-browser.nvim", - enabled = false, - event = "VeryLazy", - dependencies = { - "nvim-telescope/telescope.nvim", - "nvim-lua/plenary.nvim" - }, - config = function() - require("telescope").load_extension("file_browser") - vim.keymap.set("n", "fb", "Telescope file_browser", "File browser") - end, -} diff --git a/.config/nvim/lua/plugins/telescope.lua b/.config/nvim/lua/plugins/telescope.lua index baac8a1..8da526e 100644 --- a/.config/nvim/lua/plugins/telescope.lua +++ b/.config/nvim/lua/plugins/telescope.lua @@ -1,8 +1,27 @@ return { "nvim-telescope/telescope.nvim", - event = "VeryLazy", - config = true, dependencies = { - "nvim-lua/plenary.nvim" + "nvim-lua/plenary.nvim", + "nvim-telescope/telescope-project.nvim", }, + keys = { + {"f", "Telescope find_files", desc = "Find files"}, + {"r", "Telescope oldfiles", desc = "Recent files"}, + {"p", "Telescope project", desc = "Projects"}, + }, + config = function() + require("telescope").setup({ + extensions = { + project = { + base_dirs = { + { path = "~/projects", max_depth = 2 }, + }, + order_by = "desc", + sync_with_nvim_tree = true, + theme = "dropdown", + }, + }, + }) + require("telescope").load_extension("project") + end, } diff --git a/.config/nvim/lua/plugins/term.lua b/.config/nvim/lua/plugins/term.lua deleted file mode 100644 index d936142..0000000 --- a/.config/nvim/lua/plugins/term.lua +++ /dev/null @@ -1,5 +0,0 @@ -return { - "NvChad/nvterm", - event = "VeryLazy", - config = true, -} diff --git a/.config/nvim/lua/plugins/theme.lua b/.config/nvim/lua/plugins/theme.lua index 9638edf..7d5679b 100644 --- a/.config/nvim/lua/plugins/theme.lua +++ b/.config/nvim/lua/plugins/theme.lua @@ -5,6 +5,7 @@ return { opts = { style = "dark", transparent = false, + term_colors = true, }, config = function(_, opts) local theme = require("onedark") diff --git a/.config/nvim/lua/plugins/tree.lua b/.config/nvim/lua/plugins/tree.lua index a19f781..ed30fb0 100644 --- a/.config/nvim/lua/plugins/tree.lua +++ b/.config/nvim/lua/plugins/tree.lua @@ -4,14 +4,26 @@ return { dependencies = { "nvim-tree/nvim-web-devicons", }, - config = function() - require("nvim-tree").setup({ - view = { - width = 35, - }, - renderer = { - root_folder_label = false - }, - }) + opts = { + filesystem_watchers = { + enable = true, + }, + filters = { + dotfiles = false, + }, + renderer = { + root_folder_label = false + }, + sync_root_with_cwd = true, + update_focused_file = { + enable = true, + update_root = false, + }, + view = { + width = 35, + }, + }, + config = function(_, opts) + require("nvim-tree").setup(opts) end, }