Page content

Plugin Manager Install

Most plugin managers are very simple to install and setup and need very little besides a script. Since I am using Lazy, https://github.com/folke/lazy.nvim, here is a summary of what to do.
In the root of the config file location, add a file named init.lua and add the following code…

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, opts)

I like to do things a little different than what is written there. As you can see there are a few different ways to get things setup because of the different approaches. If you want to do it different you can.

My init.lua file the following below.

require("lazy-setup")

-- OS specific config files
local has = function(x)
  return vim.fn.has(x) == 1
end

local is_mac = has("macunix")
local is_win = has("win32")

if is_mac then
  require("config.macos")
end
if is_win then
  require("config.windows")
end

All of this is in the directory ~/.config/nvim/
From here, you will notice that the “require statements” actually are dot notated and look more like words than a directory.
All of these are in the subdirectory of lua, which if its not already in the ~/.config/nvim/ then you should make it there. From that lua directory, all files are referenced.
Then anything with a dot is a subdirectory of that lua one and referencing that file.

My directory structure looks something like this…

  • .config/
    • nvim/
      • init.lua
      • lua/
        • config/
          • macos.lua
          • windows.lua
        • plugins/
        • lazy-setup.lua

Notice that the first line of my init.lua file references the file lazy-setup.lua in the lua/ directory. And notice that you don’t need to reference the .lua at the end of the files either. So my mac specific setup is in the config/ directory as the file named macos.lua.
You don’t need this, but I saw a few other people do this, and I use the same config, currently, on my mac and windows pcs. That will probably change soon.

In the plugins/ directory is where all the different specs or configs for the different plugins will reside.

In that file lazy-setup.lua, which is in the path ~/.config/nvim/lua/ is the code from the repo that I first mentioned to set things up.

I have things setup like this for IF/WHEN I want to change package managers. In theory, I can easily fall back to one while transferring specs over with only 1 line of code.
Actually, mine is a little different, from what I wrote above, but its derived from the repo.

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- bootstrap lazy.nvim
  -- stylua: ignore
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable",
    lazypath
  })
end
vim.opt.rtp:prepend(vim.env.LAZY or lazypath)

require("lazy").setup({
  spec = {
    -- reference to the folders and files for the setup  
    { import = "plugins" },
    { import = "plugins.lsp" },
  },
  defaults = {
    -- By default, only LazyVim plugins will be lazy-loaded. Your custom plugins will load during startup.
    -- If you know what you're doing, you can set this to `true` to have all your custom plugins lazy-loaded by default.
    lazy = false,
    -- It's recommended to leave version=false for now, since a lot the plugin that support versioning,
    -- have outdated releases, which may break your Neovim install.
    version = false, -- always use the latest git commit
    -- version = "*", -- try installing the latest stable version for plugins that support semver
  },
  install = {
    colorscheme = { "onedark" },
  },
  -- automatically check for plugin updates
  checker = {
    enabled = true,
    notify = true,
  },
  change_detection = {
    notify = true,
  },
  performance = {
    rtp = {
      -- disable some rtp plugins
      disabled_plugins = {
        -- "gzip",
        -- "matchit",
        -- "matchparen",
        -- "netrwPlugin",
        -- "tarPlugin",
        -- "tohtml",
        -- "tutor",
        -- "zipPlugin",
      },
    },
  },
  ui = {},
  -- dev = { },
  -- debug = false,
})

This I think is fairly straightforward. I added some options that are listed elsewhere in the docs and changed the defaults. From there I also added the spec = {} attribute to reference the folder of all the specs I want to install. It does not have to be a single file, but it can be a folder and then it will load all the files in there.