vimtricks.wiki Concise Vim tricks, one at a time.

How do I manage Neovim plugins with lazy loading using lazy.nvim?

Answer

:Lazy

Explanation

lazy.nvim is the modern standard for Neovim plugin management. It supports lazy loading (plugins load only when needed), lockfiles for reproducibility, a beautiful UI, and automatic installation — significantly improving startup time.

How it works

  • :Lazy — opens the lazy.nvim management UI
  • :Lazy sync — install, update, and clean plugins in one step
  • :Lazy profile — shows startup time profiling for each plugin
  • Plugins can be configured to load on events, commands, keys, or filetypes

Example

" In init.lua — add a plugin with lazy loading
require('lazy').setup({
  {
    'nvim-telescope/telescope.nvim',
    cmd = 'Telescope',           -- load only when :Telescope is used
    keys = { '<leader>ff' },     -- or when this key is pressed
    dependencies = { 'nvim-lua/plenary.nvim' },
  },
})
:Lazy UI shows:
● telescope.nvim    loaded on cmd: Telescope    42ms
● plenary.nvim      loaded as dependency        5ms
○ other-plugin      not yet loaded

Tips

  • Use event = 'VeryLazy' for plugins needed eventually but not at startup
  • ft = 'python' loads only for Python files
  • lazy-lock.json pins exact versions — commit it for reproducible setups
  • :Lazy profile helps identify slow plugins hurting startup time

Next

How do I return to normal mode from absolutely any mode in Vim?