lazy.nvim is a plugin manager for nvim that was released in November 2022. It makes nvim start up quickly and automatically installs plugins.
Install lazy.nvim with the following script. Lua package manager luarocks is required.
$ brew install luarocks
$ cat ~/.config/nvim/init.lua
-- Bootstrap lazy.nvim
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or vim.loop).fs_stat(lazypath) then
local lazyrepo = "https://github.com/folke/lazy.nvim.git"
local out = vim.fn.system({ "git", "clone", "--filter=blob:none", "--branch=stable", lazyrepo, lazypath })
if vim.v.shell_error ~= 0 then
vim.api.nvim_echo({
{ "Failed to clone lazy.nvim:\n", "ErrorMsg" },
{ out, "WarningMsg" },
{ "\nPress any key to exit..." },
}, true, {})
vim.fn.getchar()
os.exit(1)
end
end
vim.opt.rtp:prepend(lazypath)
-- Make sure to setup `mapleader` and `maplocalleader` before
-- loading lazy.nvim so that mappings are correct.
-- This is also a good place to setup other settings (vim.opt)
vim.g.mapleader = " "
vim.g.maplocalleader = "\\"
-- Setup lazy.nvim
require("lazy").setup({
spec = {
-- add your plugins here
},
-- Configure any other settings here. See the documentation for more details.
-- colorscheme that will be used when installing plugins.
install = { colorscheme = { "habamax" } },
-- automatically check for plugin updates
checker = { enabled = true },
})
When nvim is started, the script is executed and the repository is cloned.
# :exec 'echo stdpath("data")'
***/.local/share/nvim
# !ls ***/.local/share/nvim
CHANGELOG.md README.md bootstrap.lua lua scripts stylua.toml vim.toml
LICENSE TODO.md doc manifest selene.toml tests
Check if it’s working properly.
# :checkhealth lazy
==============================================================================
lazy: require("lazy.health").check()
lazy.nvim ~
- {lazy.nvim} version `11.14.1`
- OK {git} `version 2.39.2 (Apple Git-143)`
- OK no existing packages found by other package managers
- OK packer_compiled.lua not found
luarocks ~
- checking `luarocks` installation
- OK no plugins require `luarocks`, so you can ignore any warnings below
- OK {luarocks} `/opt/homebrew/bin/luarocks 3.11.1`
- WARNING `lua` version `5.1` needed, but found `Lua 5.4.7 Copyright (C) 1994-2024 Lua.org, PUC-Rio`
- WARNING {lua5.1} or {lua} or {lua-5.1} version `5.1` not installed
The UI opens with :Lazy.
Install telescope.nvim, which is a fuzzy finder. Write it directly or write it to lua files in the ~/.config/nvim/lua/plugins directory and import it. Also install ripgrep for live grep.
spec = {
{
'nvim-telescope/telescope.nvim', tag = '0.1.8',
dependencies = { 'nvim-lua/plenary.nvim' } -- & brew install ripgrep for live grep
}
-- { import = "plugins" },
},
You can search for and open files with previews using :Telescope find_files. C-t to open in a new tab.
Set keymap.
vim.g.mapleader = " "
local builtin = require('telescope.builtin')
vim.keymap.set('n', '<leader>ff', builtin.find_files, { desc = 'Telescope find files' })
vim.keymap.set('n', '<leader>fg', builtin.live_grep, { desc = 'Telescope live grep' })
Set colorscheme, display mode etc. below by lualine.nvim and file explorer by neo-tree.nvim, and make Copilot available.
{
{
"EdenEast/nightfox.nvim",
config = function()
vim.cmd("colorscheme carbonfox")
end
},
{
'nvim-lualine/lualine.nvim',
dependencies = { 'nvim-tree/nvim-web-devicons' },
config = function()
...
end
},
{
'github/copilot.vim',
-- :Copilot setup
}
}