Skip to content
Darrion Burgess edited this page Nov 20, 2023 · 1 revision

Since Lazy.nvim is the primary engine driving all of this, we should take a second to review how it is setup incase we ever need to make changes ourselves

Bootstrapping Lazy

One of the most important steps that LazyVim is trying to take care of is the edge case where you don't have lazy itself installed, which will then install all the other plugins.

We achieve that with this snippet:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  -- 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)
  1. First, we make a path that goes from the standard data path (usually ~/.local/share/nvim/), and append /lazy/lazy.nvim to the end
  2. If we find the lazypath is not available, likely because we don't have lazy, we pull it using git
    1. We are just pulling directly from the git CLI, we only grab the stable version
  3. Finally, we prepend either the new lazypath or the LAZY enviroment variable if it exists

Setup

Lazy needs to be setup with the setup function, but this is usually a big table of options, so to make it easier to read, we will be creating some of the larger configuration chunks as local variable tables and incorporating them into the final function call in the end

LazyVim Extras

The spec is the actual list of plugins to be installed, and helps us easily add and remove plugins we want

local spec_list = {
  {"LazyVim/LazyVim", import = "lazyvim.plugins"},
  {{- if ne .chezmoi.hostname "USMINDARBURGES1"}}
  { import = "lazyvim.plugins.extras.coding.copilot"},
  {{- end }}
  {import = "lazyvim.plugins.extras.ui.mini-animate"},
  {import = "lazyvim.plugins.extras.editor.mini-files"},
  {import = "lazyvim.plugins.extras.ui.edgy"},
  {import = "lazyvim.plugins.extras.editor.aerial"},
  {import = "lazyvim.plugins.extras.util.mini-hipatterns"},
  {import = "lazyvim.plugins.extras.util.project"},
  {import = "lazyvim.plugins.extras.dap.core"},
  {import = "lazyvim.plugins.extras.formatting.black" },
  {import = "lazyvim.plugins.extras.test.core"},
  {import = "lazyvim.plugins.extras.vscode"},
  {import = "lazyvim.plugins.extras.coding.yanky"},
  {import = "lazyvim.plugins.extras.lang.rust"},
  {import = "lazyvim.plugins.extras.lang.python"},
  {import = "plugins"},
}
  1. We install the various plugins that come with LazyVim
    1. it should be noted that lazyvim actually comes with extra plugins that users don't need to activate immediately
      1. we can import them with any of the extra files in lazyvim itself
  2. Speaking of which, we add the copilot extra here instead of our own home-rolled version so that I might even be able to just update the copilot work?
    1. Do note, in order to keep the setup compliant, we ensure this only gets added if we are not on our work machine, ensuring compliance with the license
  3. We import the project plugin, which is a plugin that helps us with quickly changing to different project folders
  4. we import mini-animate for that sweet-sweet scrolling animation
  5. edgy is an interesting plugin that makes an abstraction layer around windows that are usually created around the end, we use this to make a fairly compelling upgrade to the workflow of having multiple windows open at once, with the ability to cycle and close them all with a few hotkeys
  6. mini-hipatterns is a simple plugin that highlights color codes with the color they represent, useful for debugging design elements
  7. dap core gives us the debug adapter protocol which gives us a language-agnostic debugger at our fingertips
  8. test.core sets up the neotest framework with a few starter languages and the default hotkeys so you can do all of your testing from the different files
  9. We even have vscode support working from lazy! giving us a stable experience when we need to break out the vscode editor
  10. Flash is a replacement for leap.nvim and has various motion hotkeys that enable us to jump around the page horizontally in a way that is pleasing to the eyes and actually leverages technology like treesitter to allow us to jump around code using the treesitter nodes themselves
  11. Yanky is an abstraction layer over the yanking experience to give us the experience of yanking text and putting it that we deserve
  12. We import the any *.lua files found within the plugins folder of the lua directory
    1. This is the primary way we do additional plugins as a user, and can be changed if we want multiple directories for plugins

Performance

Lazy prides itself on keeping startup time and general editor speed snappy, he also gives the ability to tweak the performance even more so you can find the balance that works right for you Here is our initial performance layout:

local performance_settings = {
  rtp = {
    disabled_plugins = {
      "gzip",
      "tarPlugin",
      "tohtml",
      "tutor",
      "zipPlugin",
    },
  },
}
  • Here, all we are really doing is removing some of the plugins that comes with vim
    • The implicit understanding is that you neither use, nor care about these tools and since they are written in vimscript primarily, removing them will improve performance

Bringing it All Together

We call the setup function itself and use the tables we assembled before as a part of our larger configuration of Lazy

require("lazy").setup({
  spec = spec_list,
  defaults = {
    lazy = false,
    version = false,
  },
  install = { colorscheme = { "tokyonight", "habamax" } },
  checker = { enabled = true },
  performance = performance_settings,
})
  • we default to immediately loading new plugins
    • This helps to reduce the amount of frustration of lazy-loading related bugs at first
      • The implicit message is that you should make plugins lazy as you need, rather than starting from a lazy view and dealing with dependency hell
  • version
    • This allows us to try and install the latest stable version of our plugins by default
      • however, this assumes the person implemented SemVer in their repo, and for right now we cant be sure of that so version is set to false for now
        • might be interesting to see if turning this on breaks a bunch of stuff or if the community of coalescing around semver
  • When we initially load up lazy to get plugins, we can set the colorscheme of the window that shows up
    • This just ensures consistency between the style you normally have and the style you have otherwise
      • Also colorschemes are tricky when it comes to installation so getting them installed quickly is a good idea
  • We also enable lazy to check on our behalf if that are updates for different plugins
    • This results in a notification when you enter neovim about the plugins that can have updates
      • if this notification gets annoying you can always disable it here
Clone this wiki locally