Managing Plugins using Lazy

Shaik Zahid
3 min readFeb 5, 2023

--

After the installation of your init.vim file in your PATH/nvim directory and lazy-config.lua in your PATH/nvim/lua folder. It’s time to add a new file named plugins which is passed as an argument to our lazy-config.lua file so that it can load and install all the plugins separately. I will update the plugins.lua file accordingly after installing each plugin.

NOTE:-

The PATH mentioned above differs according to the Operating System.

  • Linux/ MacOS :- PATH refers to ~/ .config/
  • Windows :- PATH is .Appdata/local/

Folder Structure

  • This is the folder structure of nvim directory.
  • First we created the main configuration file init.vim.
  • Then, We went on to create a folder named lua with two files in it.
  • Lazy-config.lua is for the managing plugins.
  • Plugins.lua file is passed as an argument to lazy-config.lua file in order to install plugins in a separate file.
  • Lazy-lock.json file is an autogenerated by Lazy package manager which holds the information of plugins and their commits. As most of the plugins are stored in Github.

Setting Up Our Plugins File

  • Initially, all we have to do is to add the following code to our lazy-config.lua file, so our file becomes like this
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)

-- Added this line to our initial lazy-config.lua file (Remove this comment if you want to)
require("lazy").setup('plugins')
  • After configuring this lazy-config.lua file correctly, A new autogenerated file named “lazy-lock.json” file will be created by our package manager to manage plugins and their commits.
  • Now, Open the plugins.lua file from your lua directory and add a return statement with empty braces to get started with your plugin management.
return { 
-- Plugins will be added here accordingly.
}
  • After setting these files, Your Lazy Package Manager UI will look like this.
  • More plugins will be added and managed by Lazy package manager as we go on improving our developer experience using Neovim IDE.

Neovim From Scratch

  • If you want a complete installation and configuration of Neovim from Scratch, then you can head over to my NEOVIM SERIES.
  • This series is updated regularly, with updates and inclusion of newer plugins which improves the wholesome IDE experience of Neovim.

--

--