From 3f978bcd09846abe2d88863521753db7f10e9a53 Mon Sep 17 00:00:00 2001 From: Gabriel Arazas Date: Fri, 27 Oct 2023 19:29:23 +0800 Subject: [PATCH] nvim: migrate from packer.nvim to lazy.nvim --- nvim/init.lua | 17 +- nvim/lazy-lock.json | 29 +++ nvim/lua/plugins.lua | 301 ------------------------------ nvim/lua/plugins/appearance.lua | 20 ++ nvim/lua/plugins/fuzzy-finder.lua | 90 +++++++++ nvim/lua/plugins/languages.lua | 14 ++ nvim/lua/plugins/lsp.lua | 59 ++++++ nvim/lua/plugins/snippets.lua | 50 +++++ nvim/lua/plugins/tree-sitter.lua | 53 ++++++ 9 files changed, 330 insertions(+), 303 deletions(-) create mode 100644 nvim/lazy-lock.json delete mode 100644 nvim/lua/plugins.lua create mode 100644 nvim/lua/plugins/appearance.lua create mode 100644 nvim/lua/plugins/fuzzy-finder.lua create mode 100644 nvim/lua/plugins/languages.lua create mode 100644 nvim/lua/plugins/lsp.lua create mode 100644 nvim/lua/plugins/snippets.lua create mode 100644 nvim/lua/plugins/tree-sitter.lua diff --git a/nvim/init.lua b/nvim/init.lua index d54c29a..40197c9 100644 --- a/nvim/init.lua +++ b/nvim/init.lua @@ -1,7 +1,20 @@ -- vim: shiftwidth=2 --- Activating my own modules ala-Doom Emacs. -require("plugins") +-- Bootstrapping for the package manager +local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim" +if not vim.loop.fs_stat(lazypath) then + vim.fn.system({ + "git", + "clone", + "--filter=blob:none", + "https://github.com/folke/lazy.nvim.git", + "--branch=stable", -- latest stable release + lazypath, + }) +end +vim.opt.rtp:prepend(lazypath) + +require("lazy").setup("plugins") require("lsp-user-config").setup() vim.g["mapleader"] = " " diff --git a/nvim/lazy-lock.json b/nvim/lazy-lock.json new file mode 100644 index 0000000..40ef68c --- /dev/null +++ b/nvim/lazy-lock.json @@ -0,0 +1,29 @@ +{ + "LuaSnip": { "branch": "master", "commit": "80a8528f084a97b624ae443a6f50ff8074ba486b" }, + "ale": { "branch": "master", "commit": "53b01d6a546384a28f1ccbed41baae58d7341da4" }, + "cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" }, + "cmp-nvim-lsp": { "branch": "main", "commit": "44b16d11215dce86f253ce0c30949813c0a90765" }, + "cmp-nvim-lua": { "branch": "main", "commit": "f12408bdb54c39c23e67cab726264c10db33ada8" }, + "cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" }, + "cmp_luasnip": { "branch": "master", "commit": "05a9ab28b53f71d1aece421ef32fee2cb857a843" }, + "dhall-vim": { "branch": "master", "commit": "68500ef46ff3706f46c99db3be7a0c8abcf6a3ae" }, + "editorconfig-vim": { "branch": "master", "commit": "0d54ea863089fb13be423b4aed6cca35f3a5d778" }, + "friendly-snippets": { "branch": "main", "commit": "43727c2ff84240e55d4069ec3e6158d74cb534b6" }, + "harpoon": { "branch": "master", "commit": "c1aebbad9e3d13f20bedb8f2ce8b3a94e39e424a" }, + "lazy.nvim": { "branch": "main", "commit": "28a80136b5253a8de6dea87f335919ac9f67116d" }, + "lush.nvim": { "branch": "main", "commit": "966aad1accd47fa11fbe2539234f81f678fef2de" }, + "nvim-base16": { "branch": "master", "commit": "0b62f6e40e213e9e60b913ebd3be73373fc145d1" }, + "nvim-cmp": { "branch": "main", "commit": "51260c02a8ffded8e16162dcf41a23ec90cfba62" }, + "nvim-colorizer.lua": { "branch": "master", "commit": "36c610a9717cc9ec426a07c8e6bf3b3abcb139d6" }, + "nvim-dap": { "branch": "master", "commit": "3eb26a63a3674e3722182a92f21d04c4e5ce0f43" }, + "nvim-lspconfig": { "branch": "master", "commit": "cb49a4cd622d7ed775c31561bb8aa6a50712d6b9" }, + "nvim-treesitter": { "branch": "master", "commit": "3954741f2652fbcef9d6877d0e3a4d91d44b1632" }, + "nvim-treesitter-textobjects": { "branch": "master", "commit": "e69a504baf2951d52e1f1fbb05145d43f236cbf1" }, + "plenary.nvim": { "branch": "master", "commit": "50012918b2fc8357b87cff2a7f7f0446e47da174" }, + "telescope.nvim": { "branch": "master", "commit": "4522d7e3ea75ffddabdc39957168a8a7060b5df0" }, + "vim-airline": { "branch": "master", "commit": "3b9e149e19ed58dee66e4842626751e329e1bd96" }, + "vim-gitgutter": { "branch": "main", "commit": "f7b97666ae36c7b3f262f3190dbcd7033845d985" }, + "vim-nix": { "branch": "master", "commit": "1e8d3cc4d74f40fb384cd1739739543fe117ff61" }, + "vimspector": { "branch": "master", "commit": "831530b85aad02f2c465047a21452409bfaaf784" }, + "zig.vim": { "branch": "master", "commit": "54c216e5306a5c3878a60596aacb94dca8652ab9" } +} \ No newline at end of file diff --git a/nvim/lua/plugins.lua b/nvim/lua/plugins.lua deleted file mode 100644 index 4eca2d6..0000000 --- a/nvim/lua/plugins.lua +++ /dev/null @@ -1,301 +0,0 @@ --- This is where I install my package manager and plugins of choice. For more --- details, just look for `packger.nvim` help tag. - --- Bootstrapping for the package manager -local install_path = vim.fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim" - -if vim.fn.empty(vim.fn.glob(install_path)) > 0 then - packer_bootstrap = vim.fn.system({ "git", "clone", "https://github.com/wbthomason/packer.nvim", install_path }) -end - -local packer = require("packer") -local util = require("packer.util") - -return packer.startup({ - function(use) - -- Let the package manager manage itself. - use({ "wbthomason/packer.nvim" }) - - -- Custom color themes! - use({ "rktjmp/lush.nvim" }) - - -- EditorConfig plugin - use({ "editorconfig/editorconfig-vim" }) - - -- Colorize common color strings - use({ - "norcalli/nvim-colorizer.lua", - config = function() - require("colorizer").setup() - end, - }) - - -- Snippets engine. - -- A must have for me. - use({ - "L3MON4D3/LuaSnip", - requires = { - "rafamadriz/friendly-snippets", - }, - config = function() - require("luasnip.loaders.from_vscode").lazy_load() - require("luasnip.loaders.from_lua").lazy_load() - - local ls = require("luasnip") - local types = require("luasnip.util.types") - ls.config.set_config({ - history = true, - update_events = "TextChanged,TextChangedI", - ext_opts = { - [types.choiceNode] = { - active = { - virt_text = { { "<- Current choice", "Comment" } }, - }, - }, - }, - }) - - vim.keymap.set({ "i", "s" }, "", function() - if ls.jumpable(1) then - ls.jump(1) - end - end) - - vim.keymap.set({ "i", "s" }, "", function() - if ls.jumpable(-1) then - ls.jump(-1) - end - end) - - vim.keymap.set({ "i", "s" }, "", function() - if ls.expand_or_jumpable() then - ls.expand_or_jump() - end - end) - - vim.keymap.set({ "i", "s" }, "", function() - require("luasnip.extras.select_choice")() - end) - end, - }) - - -- Fuzzy finder of lists - use({ - "nvim-telescope/telescope.nvim", - requires = { - { "nvim-lua/popup.nvim" }, - { "nvim-lua/plenary.nvim" }, - { "nvim-telescope/telescope-project.nvim" }, - }, - - config = function() - -- Telescope setup - require("telescope").setup({ - extensions = { - project = { - base_dirs = { - { "~/library/projects/software", max_depth = 2 }, - { "~/library/projects/packages" }, - { "~/library/writings" }, - }, - }, - }, - }) - - require("telescope").load_extension("project") - - vim.keymap.set( - "n", - "ff", - 'lua require("telescope.builtin").find_files({ hidden = true })', - { noremap = true } - ) - vim.keymap.set( - "n", - "fF", - 'lua require("telescope.builtin").find_files({ cwd = require("telescope.utils").buffer_dir(), hidden = true })', - { noremap = true } - ) - vim.keymap.set("n", "fg", 'lua require("telescope.builtin").grep_string()', { noremap = true }) - vim.keymap.set("n", "fG", 'lua require("telescope.builtin").live_grep()', { noremap = true }) - vim.keymap.set("n", "fb", 'lua require("telescope.builtin").buffers()', { noremap = true }) - vim.keymap.set("n", "fh", 'lua require("telescope.builtin").help_tags()', { noremap = true }) - vim.keymap.set("n", "ft", 'lua require("telescope.builtin").treesitter()', { noremap = true }) - vim.keymap.set("n", "fb", 'lua require("telescope.builtin").buffers()', { noremap = true }) - vim.keymap.set("n", "fr", 'lua require("telescope.builtin").oldfiles()', { noremap = true }) - vim.keymap.set( - "n", - "fR", - 'lua require("telescope.builtin").oldfiles({ only_cwd = true })', - { noremap = true } - ) - vim.keymap.set("n", "fA", 'lua require("telescope.builtin").resume()', { noremap = true }) - - -- Ekeymap.set - vim.keymap.set( - "n", - "fp", - 'lua require("telescope").extensions.project.project({})', - { noremap = true } - ) - end, - }) - - -- Marks in ~~steroids~~ coconut oil - use({ - "ThePrimeagen/harpoon", - config = function() - vim.keymap.set("n", "fm", "lua require('harpoon.mark').add_file()", {}) - - local has_telescope, telescope = pcall("telescope") - if has_telescope then - vim.keymap.set("n", "fM", "lua require('telescope').extensions.harpoon.harpoon({})", {}) - require("telescope").load_extension("harpoon") - end - end, - requires = { { "nvim-lua/plenary.nvim" } }, - }) - - -- A completion engine. - -- nvim-cmp is mostly explicit by making the configuration process manual unlike bigger plugins like CoC - use({ - "hrsh7th/nvim-cmp", - requires = { - "hrsh7th/cmp-buffer", - "hrsh7th/cmp-path", - "hrsh7th/cmp-nvim-lsp", - "hrsh7th/cmp-nvim-lua", - "saadparwaiz1/cmp_luasnip", - }, - config = function() - local cmp = require("cmp") - - cmp.setup({ - snippet = { - expand = function(args) - ls.lsp_expand(args.body) - end, - }, - - sources = { - { name = "luasnip" }, - { name = "buffer" }, - { name = "path" }, - { name = "nvim_lua" }, - { name = "nvim_lsp" }, - }, - - mapping = { - [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), - [""] = cmp.mapping(cmp.mapping.confirm({ select = true }), { "i", "c" }), - [""] = cmp.mapping({ - i = cmp.mapping.abort(), - c = cmp.mapping.close(), - }), - }, - }) - end, - }) - - -- A linting engine, a DAP client, and an LSP client entered into a bar. - use({ - "dense-analysis/ale", - config = function() - vim.g.ale_disable_lsp = 1 - end, - }) - use({ "neovim/nvim-lspconfig" }) - use({ "mfussenegger/nvim-dap" }) - use({ "puremourning/vimspector" }) - - -- tree-sitter - use({ - "nvim-treesitter/nvim-treesitter", - requires = { - "nvim-treesitter/nvim-treesitter-textobjects", - }, - run = ":TSUpdate", - config = function() - vim.opt.foldmethod = "expr" - vim.opt.foldexpr = "nvim_treesitter#foldexpr()" - - require("nvim-treesitter.configs").setup({ - highlight = { - enable = true, - additional_vim_regex_highlighting = false, - }, - - incremental_selection = { - enable = true, - keymaps = { - init_selection = "gnn", - node_incremental = "grn", - scope_incremental = "grc", - node_decremental = "grm", - }, - }, - - indent = { enable = true }, - - -- custom text objects with nvim-treesitter-textobjects - -- I've just copied this from the README but they are reasonable additions to me. - textobjects = { - select = { - enable = true, - lookahead = true, - - keymaps = { - ["af"] = "@function.outer", - ["if"] = "@function.inner", - ["ae"] = "@block.outer", - ["ie"] = "@block.inner", - ["ac"] = "@class.outer", - ["ic"] = "@class.inner", - ["aC"] = "@conditional.outer", - ["iC"] = "@conditional.inner", - }, - }, - }, - }) - end, - }) - - -- One of the most popular plugins. - -- Allows to create more substantial status bars. - use({ "vim-airline/vim-airline" }) - - -- Fuzzy finder for finding files freely and fastly. - use({ - "junegunn/fzf", - requires = "junegunn/fzf.vim", - }) - - -- Enable visuals for addition/deletion of lines in the gutter (side) similar to Visual Studio Code. - use({ "airblade/vim-gitgutter" }) - - -- Language plugins. - use({ "LnL7/vim-nix" }) -- Nix - use({ "vmchale/dhall-vim" }) -- Dhall - use({ "ziglang/zig.vim" }) -- Zig - - use({ "RRethy/nvim-base16" }) - - -- Use Neovim even inside of browsers. - use({ - "glacambre/firenvim", - run = function() - vim.fn["firenvim#install"](0) - end, - }) - - use({ "https://gitlab.com/HiPhish/guile.vim.git" }) - use({ "Olical/conjure" }) - end, - config = { - compile_path = util.join_paths(vim.fn.stdpath("data"), "site", "after", "plugin", "packer_compiled.lua"), - }, -}) diff --git a/nvim/lua/plugins/appearance.lua b/nvim/lua/plugins/appearance.lua new file mode 100644 index 0000000..f9a3d1c --- /dev/null +++ b/nvim/lua/plugins/appearance.lua @@ -0,0 +1,20 @@ +return { + -- Enable visuals for addition/deletion of lines in the gutter (side) similar + -- to Visual Studio Code. + "airblade/vim-gitgutter", + + -- Base16 support + "RRethy/nvim-base16", + + -- Make your Neovim pretty + "rktjmp/lush.nvim", + + -- More useful status bar + "vim-airline/vim-airline", + + -- Colorize common color strings + { + "norcalli/nvim-colorizer.lua", + config = true, + } +} diff --git a/nvim/lua/plugins/fuzzy-finder.lua b/nvim/lua/plugins/fuzzy-finder.lua new file mode 100644 index 0000000..00847d9 --- /dev/null +++ b/nvim/lua/plugins/fuzzy-finder.lua @@ -0,0 +1,90 @@ +return { + { + "nvim-telescope/telescope.nvim", + depedencies = { + { "nvim-lua/popup.nvim" }, + { "nvim-lua/plenary.nvim" }, + { "nvim-telescope/telescope-project.nvim" }, + }, + config = function() + local telescope = require("telescope") + telescope.setup { + extensions = { + project = { + base_dirs = { + { "~/library/projects/software", max_depth = 2 }, + { "~/library/projects/packages" }, + { "~/library/writings" }, + }, + }, + }, + } + + telescope.load_extension("project") + + local builtins = require("telescope.builtin") + local get_builtin = function(fun, ...) + local fargs = arg + return function() + builtins[fun](fargs) + end + end + + vim.keymap.set( + "n", + "ff", + get_builtin("find_files", { hidden = true }), + { noremap = true } + ) + vim.keymap.set( + "n", + "fF", + function() + builtins.find_files { + cwd = require("telescope.utils").buffer_dir(), + hidden = true, + } + end, + { noremap = true } + ) + + vim.keymap.set("n", "fg", get_builtin "grep_string", { noremap = true }) + vim.keymap.set("n", "fG", get_builtin "live_grep", { noremap = true }) + vim.keymap.set("n", "fb", get_builtin "buffers" , { noremap = true }) + vim.keymap.set("n", "fh", get_builtin "help_tags", { noremap = true }) + vim.keymap.set("n", "ft", get_builtin "treesitter", { noremap = true }) + vim.keymap.set("n", "fb", get_builtin "buffers", { noremap = true }) + vim.keymap.set("n", "fr", get_builtin "old_files", { noremap = true }) + vim.keymap.set( + "n", + "fR", + get_builtin("old_files", { only_cwd = true }), + { noremap = true } + ) + vim.keymap.set("n", "fA", get_builtin "resume", { noremap = true }) + + -- Ekeymap.set + vim.keymap.set( + "n", + "fp", + 'lua require("telescope").extensions.project.project({})', + { noremap = true } + ) + end, + }, + + -- Marks in ~~steroids~~ coconut oil + { + "ThePrimeagen/harpoon", + config = function() + vim.keymap.set("n", "fm", "lua require('harpoon.mark').add_file()", {}) + + local has_telescope, telescope = pcall("telescope") + if has_telescope then + vim.keymap.set("n", "fM", "lua require('telescope').extensions.harpoon.harpoon({})", {}) + require("telescope").load_extension("harpoon") + end + end, + dependencies = { { "nvim-lua/plenary.nvim" } }, + } +} diff --git a/nvim/lua/plugins/languages.lua b/nvim/lua/plugins/languages.lua new file mode 100644 index 0000000..1a47c16 --- /dev/null +++ b/nvim/lua/plugins/languages.lua @@ -0,0 +1,14 @@ +-- A bunch of plugins for programming languages support. +return { + -- EditorConfig plugin. + "editorconfig/editorconfig-vim", + + -- Nix + "LnL7/vim-nix", + + -- Dhall + "vmchale/dhall-vim", + + -- Zig + "ziglang/zig.vim", +} diff --git a/nvim/lua/plugins/lsp.lua b/nvim/lua/plugins/lsp.lua new file mode 100644 index 0000000..0a9ec66 --- /dev/null +++ b/nvim/lua/plugins/lsp.lua @@ -0,0 +1,59 @@ +return { + -- A completion engine. + -- nvim-cmp is mostly explicit by making the configuration process manual unlike bigger plugins like CoC + { + "hrsh7th/nvim-cmp", + dependencies = { + "hrsh7th/cmp-buffer", + "hrsh7th/cmp-path", + "hrsh7th/cmp-nvim-lsp", + "hrsh7th/cmp-nvim-lua", + "saadparwaiz1/cmp_luasnip", + }, + event = "InsertEnter", + config = function() + local cmp = require("cmp") + + cmp.setup({ + sources = { + { name = "luasnip" }, + { name = "buffer" }, + { name = "path" }, + { name = "nvim_lua" }, + { name = "nvim_lsp" }, + }, + + mapping = { + [""] = cmp.mapping(cmp.mapping.complete(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(-4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.scroll_docs(4), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.select_next_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.select_prev_item(), { "i", "c" }), + [""] = cmp.mapping(cmp.mapping.confirm({ select = true }), { "i", "c" }), + [""] = cmp.mapping({ + i = cmp.mapping.abort(), + c = cmp.mapping.close(), + }), + }, + }) + end, + }, + + -- A linting engine, a DAP client, and an LSP client entered into a bar. + { + "dense-analysis/ale", + config = function() + vim.g.ale_disable_lsp = 1 + end, + }, + + -- A bunch of pre-configured LSP configurations. + "neovim/nvim-lspconfig", + + -- Attach it with a debugger. + "mfussenegger/nvim-dap", + + -- Vimspector Gadget. + "puremourning/vimspector", + +} diff --git a/nvim/lua/plugins/snippets.lua b/nvim/lua/plugins/snippets.lua new file mode 100644 index 0000000..46bd66a --- /dev/null +++ b/nvim/lua/plugins/snippets.lua @@ -0,0 +1,50 @@ +-- Snippets engine. A must have for me. +return { + { + "L3MON4D3/LuaSnip", + dependencies = { + "rafamadriz/friendly-snippets", + }, + config = function() + require("luasnip.loaders.from_vscode").lazy_load() + require("luasnip.loaders.from_lua").lazy_load() + + local ls = require("luasnip") + local types = require("luasnip.util.types") + ls.config.set_config({ + history = true, + update_events = "TextChanged,TextChangedI", + ext_opts = { + [types.choiceNode] = { + active = { + virt_text = { { "<- Current choice", "Comment" } }, + }, + }, + }, + }) + + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(1) then + ls.jump(1) + end + end) + + vim.keymap.set({ "i", "s" }, "", function() + if ls.jumpable(-1) then + ls.jump(-1) + end + end) + + vim.keymap.set({ "i", "s" }, "", function() + if ls.expand_or_jumpable() then + ls.expand_or_jump() + end + end) + + vim.keymap.set({ "i", "s" }, "", function() + require("luasnip.extras.select_choice")() + end) + end, + } +} + diff --git a/nvim/lua/plugins/tree-sitter.lua b/nvim/lua/plugins/tree-sitter.lua new file mode 100644 index 0000000..9cea7ff --- /dev/null +++ b/nvim/lua/plugins/tree-sitter.lua @@ -0,0 +1,53 @@ +-- tree-sitter integration with Neovim. +return { + { + "nvim-treesitter/nvim-treesitter", + dependencies = { + "nvim-treesitter/nvim-treesitter-textobjects", + }, + build = ":TSUpdate", + config = function() + vim.opt.foldmethod = "expr" + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + + require("nvim-treesitter.configs").setup({ + highlight = { + enable = true, + additional_vim_regex_highlighting = false, + }, + + incremental_selection = { + enable = true, + keymaps = { + init_selection = "gnn", + node_incremental = "grn", + scope_incremental = "grc", + node_decremental = "grm", + }, + }, + + indent = { enable = true }, + + -- custom text objects with nvim-treesitter-textobjects + -- I've just copied this from the README but they are reasonable additions to me. + textobjects = { + select = { + enable = true, + lookahead = true, + + keymaps = { + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["ae"] = "@block.outer", + ["ie"] = "@block.inner", + ["ac"] = "@class.outer", + ["ic"] = "@class.inner", + ["aC"] = "@conditional.outer", + ["iC"] = "@conditional.inner", + }, + }, + }, + }) + end, + }, +}