Skip to content

Commit

Permalink
⚡️ [Nvim] Replace the package manager with lazy.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinLwx committed Mar 1, 2024
1 parent 39d3fd3 commit 63f21a5
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 126 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -19,7 +19,7 @@ After getting familiar with more and more dotfiles, I also thought I should use
- Bottom right - <kbd>⌘ Command</kbd> + <kbd>⌥ Option</kbd> + <kbd>⌃ Control</kbd> + <kbd>k</kdb>
- Hold to quit any app - <kbd>⌘ Command</kbd> + <kbd>q</kbd>
- **Neovim**
- Package manager: [packer.nvim](https://github.com/wbthomason/packer.nvim)
- Package manager: [lazy.nvim](https://github.com/folke/lazy.nvim)
- Auto-completion
- Completion sources: [nvim-cmp](https://github.com/hrsh7th/nvim-cmp)
- Vscode-like pictograms: [lspkind.nvim](https://github.com/onsails/lspkind.nvim)
Expand Down
32 changes: 32 additions & 0 deletions nvim/lazy-lock.json
@@ -0,0 +1,32 @@
{
"LuaSnip": { "branch": "master", "commit": "8ae1dedd988eb56441b7858bd1e8554dfadaa46d" },
"cmp-buffer": { "branch": "main", "commit": "3022dbc9166796b644a841a02de8dd1cc1d311fa" },
"cmp-cmdline": { "branch": "main", "commit": "8ee981b4a91f536f52add291594e89fb6645e451" },
"cmp-nvim-lsp": { "branch": "main", "commit": "5af77f54de1b16c34b23cba810150689a3a90312" },
"cmp-path": { "branch": "main", "commit": "91ff86cd9c29299a64f968ebb45846c485725f23" },
"gitsigns.nvim": { "branch": "main", "commit": "2c2463dbd82eddd7dbab881c3a62cfbfbe3c67ae" },
"indent-blankline.nvim": { "branch": "master", "commit": "821a7acd88587d966f7e464b0b3031dfe7f5680c" },
"lazy.nvim": { "branch": "main", "commit": "28126922c9b54e35a192ac415788f202c3944c9f" },
"leap.nvim": { "branch": "main", "commit": "d74388c49da2ef51bcae0f386f1c699c8394ce6e" },
"lspkind.nvim": { "branch": "master", "commit": "1735dd5a5054c1fb7feaf8e8658dbab925f4f0cf" },
"lualine.nvim": { "branch": "master", "commit": "7d131a8d3ba5016229e8a1d08bf8782acea98852" },
"markdown-preview.nvim": { "branch": "master", "commit": "a923f5fc5ba36a3b17e289dc35dc17f66d0548ee" },
"mason-lspconfig.nvim": { "branch": "main", "commit": "21d33d69a81f6351e5a5f49078b2e4f0075c8e73" },
"mason-null-ls.nvim": { "branch": "main", "commit": "e270134d83ba59425edc53356c6fd337b61bb8dd" },
"mason.nvim": { "branch": "main", "commit": "3b5068f0fc565f337d67a2d315d935f574848ee7" },
"monokai.nvim": { "branch": "master", "commit": "b8bd44d5796503173627d7a1fc51f77ec3a08a63" },
"none-ls.nvim": { "branch": "main", "commit": "e6d3abffa77597dac35de723e11daaee2fafce77" },
"nvim-autopairs": { "branch": "master", "commit": "c6139ca0d5ad7af129ea6c89cb4c56093f2c034a" },
"nvim-cmp": { "branch": "main", "commit": "04e0ca376d6abdbfc8b52180f8ea236cbfddf782" },
"nvim-lspconfig": { "branch": "master", "commit": "9553725789be682ecd945a527ec552e489ea8534" },
"nvim-surround": { "branch": "main", "commit": "d47001f8ddf9646c24f16d2732d4d0255acd2121" },
"nvim-tree.lua": { "branch": "master", "commit": "d52fdeb0a300ac42b9cfa65ae0600a299f8e8677" },
"nvim-treesitter": { "branch": "master", "commit": "62b0bb4f24ad09f535efe44cc9d088f90dcd2498" },
"nvim-web-devicons": { "branch": "master", "commit": "0bb67ef952ea3eb7b1bac9c011281471d99a27bc" },
"plenary.nvim": { "branch": "master", "commit": "4f71c0c4a196ceb656c824a70792f3df3ce6bb6d" },
"telescope.nvim": { "branch": "0.1.x", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
"toggleterm.nvim": { "branch": "main", "commit": "193786e0371e3286d3bc9aa0079da1cd41beaa62" },
"vim-commentary": { "branch": "master", "commit": "f67e3e67ea516755005e6cccb178bc8439c6d402" },
"vim-fugitive": { "branch": "master", "commit": "2e88f14a585c014691904ba8fe39e6ea851c9422" },
"vim-markdown": { "branch": "master", "commit": "46add6c3017d3e4035dc10ffa9cb54221d8dfe1a" }
}
253 changes: 128 additions & 125 deletions nvim/lua/plugins.lua
@@ -1,149 +1,150 @@
-----------------
-- Packer.nvim --
-----------------
-- Install Packer automatically if it's not installed(Bootstraping)
-- Install Lazy.nvim automatically if it's not installed(Bootstraping)
-- Hint: string concatenation is done by `..`
local ensure_packer = function()
local fn = vim.fn
local install_path = fn.stdpath("data") .. "/site/pack/packer/start/packer.nvim"
if fn.empty(fn.glob(install_path)) > 0 then
fn.system({ "git", "clone", "--depth", "1", "https://github.com/wbthomason/packer.nvim", install_path })
vim.cmd([[packadd packer.nvim]])
return true
end
return false
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
local packer_bootstrap = ensure_packer()

-- Reload configurations if we modify plugins.lua
-- Hint
-- <afile> - replaced with the filename of the buffer being manipulated
vim.cmd([[
augroup packer_user_config
autocmd!
autocmd BufWritePost plugins.lua source <afile> | PackerSync
augroup end
]])

-- Install plugins here - `use ...`
-- Packer.nvim hints
-- after = string or list, -- Specifies plugins to load before this plugin. See "sequencing" below
-- config = string or function, -- Specifies code to run after this plugin is loaded
-- requires = string or list, -- Specifies plugin dependencies. See "dependencies".
-- ft = string or list, -- Specifies filetypes which load this plugin.
-- run = string, function, or table, -- Specify operations to be run after successful installs/updates of a plugin
return require("packer").startup(function(use)
-- Packer can manage itself
use("wbthomason/packer.nvim")

vim.opt.rtp:prepend(lazypath)

-- After installation, run `checkhealth lazy` to see if everything goes right
-- Hints:
-- build: it will be executed when a plugin is installed or updated
-- config: it will be executed when the plugin loads
-- event: Lazy-load on event
-- dependencies: A list of plugin names or plugin specs that should be loaded when the plugin loads
-- ft: Lazy-load on filetype
-- cmd: Lazy-load on command
-- init: functions are always executed during startup
require("lazy").setup({
-- LSP manager
use({ "williamboman/mason.nvim" })
use({ "williamboman/mason-lspconfig.nvim" })
use({ "neovim/nvim-lspconfig" })

"williamboman/mason.nvim",
"williamboman/mason-lspconfig.nvim",
"neovim/nvim-lspconfig",
-- Add hooks to LSP to support Linter && Formatter
use({ "nvim-lua/plenary.nvim" })
use({
{
"jay-babu/mason-null-ls.nvim",
after = "plenary.nvim",
requires = { "nvimtools/none-ls.nvim" },
config = [[require('config.mason-null-ls')]],
})

event = { "BufReadPre", "BufNewFile" },
dependencies = {
"williamboman/mason.nvim",
"nvimtools/none-ls.nvim",
},
config = function()
-- Note:
-- the default search path for `require` is ~/.config/nvim/lua
-- use a `.` as a path seperator
-- the suffix `.lua` is not needed
require("config.mason-null-ls")
end,
},
-- Vscode-like pictograms
use({ "onsails/lspkind.nvim", event = "VimEnter" })

{
"onsails/lspkind.nvim",
event = { "VimEnter" },
},
-- Auto-completion engine
-- Note:
-- the default search path for `require` is ~/.config/nvim/lua
-- use a `.` as a path seperator
-- the suffix `.lua` is not needed
use({ "hrsh7th/nvim-cmp", after = "lspkind.nvim", config = [[require('config.nvim-cmp')]] })
use({ "hrsh7th/cmp-nvim-lsp", after = "nvim-cmp" })
use({ "hrsh7th/cmp-buffer", after = "nvim-cmp" }) -- buffer auto-completion
use({ "hrsh7th/cmp-path", after = "nvim-cmp" }) -- path auto-completion
use({ "hrsh7th/cmp-cmdline", after = "nvim-cmp" }) -- cmdline auto-completion

{
"hrsh7th/nvim-cmp",
dependencies = { "lspkind.nvim" },
config = function()
require("config.nvim-cmp")
end,
},
{ "hrsh7th/cmp-nvim-lsp", dependencies = { "nvim-cmp" } },
{ "hrsh7th/cmp-buffer", dependencies = { "nvim-cmp" } }, -- buffer auto-completion
{ "hrsh7th/cmp-path", dependencies = { "nvim-cmp" } }, -- path auto-completion
{ "hrsh7th/cmp-cmdline", dependencies = { "nvim-cmp" } }, -- cmdline auto-completion
-- Code snippet engine
use("L3MON4D3/LuaSnip")
use({ "saadparwaiz1/cmp_luasnip", after = { "nvim-cmp", "LuaSnip" } })

{
"L3MON4D3/LuaSnip",
version = "v2.*",
},
-- Colorscheme
use("tanvirtin/monokai.nvim")

"tanvirtin/monokai.nvim",
-- Git integration
use("tpope/vim-fugitive")

"tpope/vim-fugitive",
-- Git decorations
use({ "lewis6991/gitsigns.nvim", config = [[require('config.gitsigns')]] })

{
"lewis6991/gitsigns.nvim",
config = function()
require("config.gitsigns")
end,
},
-- Autopairs: [], (), "", '', etc
-- it relies on nvim-cmp
use({
{
"windwp/nvim-autopairs",
after = "nvim-cmp",
config = [[require('config.nvim-autopairs')]],
})

event = "InsertEnter",
config = function()
require("config.nvim-autopairs")
end,
},
-- Code comment helper
-- 1. `gcc` to comment a line
-- 2. select lines in visual mode and run `gc` to comment/uncomment lines
use("tpope/vim-commentary")

"tpope/vim-commentary",
-- Treesitter-integration
use({
{
"nvim-treesitter/nvim-treesitter",
run = function()
local ts_update = require("nvim-treesitter.install").update({ with_sync = true })
ts_update()
build = ":TSUpdate",
config = function()
require("config.nvim-treesitter")
end,
config = [[require('config.nvim-treesitter')]],
})

},
-- Show indentation and blankline
use({ "lukas-reineke/indent-blankline.nvim", config = [[require('config.indent-blankline')]] })

{
"lukas-reineke/indent-blankline.nvim",
config = function()
require("config.indent-blankline")
end,
},
-- Status line
use({
{
"nvim-lualine/lualine.nvim",
requires = { "kyazdani42/nvim-web-devicons", opt = true },
config = [[require('config.lualine')]],
})

dependencies = { "nvim-tree/nvim-web-devicons" },
config = function()
require("config.lualine")
end,
},
-- Markdown support
use({ "preservim/vim-markdown", ft = { "markdown" } })

{ "preservim/vim-markdown", ft = { "markdown" } },
-- Markdown previewer
-- It require nodejs and yarn. Use homebrew to install first
use({
-- NOTE: It require nodejs and yarn. Use homebrew to install first
{
"iamcco/markdown-preview.nvim",
run = "cd app && npm install",
setup = function()
cmd = { "MarkdownPreviewToggle", "MarkdownPreview", "MarkdownPreviewStop" },
build = "cd app && yarn install",
init = function()
vim.g.mkdp_filetypes = { "markdown" }
end,
ft = { "markdown" },
})

},
-- File explorer
use({
{
"nvim-tree/nvim-tree.lua",
requires = {
dependencies = {
"nvim-tree/nvim-web-devicons", -- optional, for file icons
},
config = [[require('config.nvim-tree')]],
})

config = function()
require("config.nvim-tree")
end,
},
-- Smart motion
-- Usage: Enter 2-character search pattern then press a label character to
-- pick your target. Initiate the sesarch with `s`(forward) or `S`(backward)
use({
-- pick your target.
-- Initiate the sesarch with `s`(forward) or `S`(backward)
{
"ggandor/leap.nvim",
config = function()
-- See `:h leap-custom-mappings` for more details
require("leap").create_default_mappings()
end,
})

},
-- Make surrounding easier
-- ------------------------------------------------------------------
-- Old text Command New text
Expand All @@ -155,9 +156,12 @@ return require("packer").startup(function(use)
-- 'change quot*es' gzc'" "change quotes"
-- delete(functi*on calls) gzcf function calls
-- ------------------------------------------------------------------
use({
{
"kylechui/nvim-surround",
tag = "*", -- Use for stability; omit to use `main` branch for the latest features
version = "*", -- Use for stability; omit to use `main` branch for the latest features
-- You can use the VeryLazy event for things that can
-- load later and are not important for the initial UI
event = "VeryLazy",
config = function()
require("nvim-surround").setup({
-- To solve the conflicts with leap.nvim
Expand All @@ -176,23 +180,22 @@ return require("packer").startup(function(use)
},
})
end,
})

},
-- Better terminal integration
-- tag = string, -- Specifies a git tag to use. Supports '*' for "latest tag"
use({ "akinsho/toggleterm.nvim", tag = "*", config = [[require('config.toggleterm')]] })

{
"akinsho/toggleterm.nvim",
version = "*",
config = function()
require("config.toggleterm")
end,
},
-- Fuzzy finder
use({
{
"nvim-telescope/telescope.nvim",
branch = "0.1.x",
requires = { "nvim-lua/plenary.nvim" },
config = [[require('config.telescope')]]
})

-- Automatically set up your configuration after cloning packer.nvim
-- Put this at the end after all plugins
if packer_bootstrap then
require("packer").sync()
end
end)
dependencies = { "nvim-lua/plenary.nvim" },
config = function()
require("config.telescope")
end,
},
})

0 comments on commit 63f21a5

Please sign in to comment.