nvf/docs/manual/configuring/custom-plugins/lazy-method.md
2025-03-23 11:09:51 +01:00

1.2 KiB

Lazy Method

As of version 0.7, we exposed an API for configuring lazy-loaded plugins via lz.n and lzn-auto-require.

{
  config.vim.lazy.plugins = {
    "aerial.nvim" = {
      package = pkgs.vimPlugins.aerial-nvim;
      setupModule = "aerial";
      setupOpts = {
        option_name = true;
      };
      after = ''
        -- custom lua code to run after plugin is loaded
        print('aerial loaded')
      '';

      # Explicitly mark plugin as lazy. You don't need this if you define one of
      # the trigger "events" below
      lazy = true;

      # load on command
      cmd = ["AerialOpen"];

      # load on event
      event = ["BufEnter"];

      # load on keymap
      keys = [
        {
          key = "<leader>a";
          action = ":AerialToggle<CR>";
        }
      ];
    };
  };
}

LazyFile event

You can use the LazyFile user event to load a plugin when a file is opened:

{
  config.vim.lazy.plugins = {
    "aerial.nvim" = {
      package = pkgs.vimPlugins.aerial-nvim;
      event = [{event = "User"; pattern = "LazyFile";}];
      # ...
    };
  };
}

You can consider LazyFile as an alias to ["BufReadPost" "BufNewFile" "BufWritePre"]