Skip to content

Setting Up a Plugin Manager

To get started adding plugins to your Neovim configuration, you will need a plugin manager.

Why Do I Need a Plugin Manager?

Think of a plugin manager a bit like a package manager for your desktop system.

It saves you the trouble of having to dig through GitHub repositories, manually download the code for the plugin you want, make sure the scripts are in the correct place for Neovim to use, and periodically check for any new updates.

Now imagine doing this for tens or hundreds of plugins.

This is what a plugin manager will do for you auto-magically. 🪄

Installing a Plugin Manager

The current defacto plugin manager in the Neovim ecosystem is lazy.nvim.

To configure lazy, add the following code to your init.lua file or inside a file in your lua/ directory, e.g. plugins-setup.lua.

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)

Breaking Down The Code

Here’s a step-by-step breakdown of what this code does.

  1. Creates a path to the Neovim data directory:

    local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
  2. Checks whether that path exists (i.e. checks whether or not you already have lazy installed)

    if not vim.loop.fs_stat(lazypath) then
  3. If not, clones the repo (in other words installs lazy)

    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
  4. Adds lazy to Neovim’s runtimepath

    vim.opt.rtp:prepend(lazypath)

Directly after this code, the plugin manager is bootstrapped and now needs to be setup with the following line of code:

require("lazy").setup({})

Remember that require is a Lua thing, not a Neovim thing. While the first code snippet installs the plugin manager, this one runs it.

Congratulations!

You now have your very own Neovim plugin manager setup. Now it’s time to install some plugins.