<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yasushi Jinnouchi</title>
    <description>The latest articles on DEV Community by Yasushi Jinnouchi (@delphinus35).</description>
    <link>https://dev.to/delphinus35</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2071656%2F258271bb-162d-4344-88ba-91f58a05e688.png</url>
      <title>DEV Community: Yasushi Jinnouchi</title>
      <link>https://dev.to/delphinus35</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/delphinus35"/>
    <language>en</language>
    <item>
      <title>How to correctly use “dependencies” with lazy.nvim</title>
      <dc:creator>Yasushi Jinnouchi</dc:creator>
      <pubDate>Sun, 15 Sep 2024 11:38:55 +0000</pubDate>
      <link>https://dev.to/delphinus35/dont-use-dependencies-in-lazynvim-4bk0</link>
      <guid>https://dev.to/delphinus35/dont-use-dependencies-in-lazynvim-4bk0</guid>
      <description>&lt;p&gt;🔔 Note: The following is an addition.&lt;/p&gt;

&lt;p&gt;The original title was &lt;em&gt;Don't use “dependencies” in lazy.nvim&lt;/em&gt;. But I get pointed out that it is a mistake and makes users misunderstanding about lazy.nvim. So changed to more accurate one.&lt;/p&gt;

&lt;p&gt;🔔 End of addition.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://lazy.folke.io" rel="noopener noreferrer"&gt;lazy.nvim&lt;/a&gt; is the most popular plugin manager of Neovim. Typical Neovim distributions, such as &lt;a href="http://www.lazyvim.org" rel="noopener noreferrer"&gt;LazyVim&lt;/a&gt; or &lt;a href="https://nvchad.com" rel="noopener noreferrer"&gt;NvChad&lt;/a&gt;, use lazy.nvim in base, so many users use lazy.nvim without knowing it. Here I wrote one point advice to use lazy.nvim.&lt;/p&gt;

&lt;h2&gt;
  
  
  Load plugins lazily with lazy.nvim
&lt;/h2&gt;

&lt;p&gt;Usually Neovim plugins are loaded in starting Neovim itself. The time for starting Neovim should become larger and larger when you add more and more plugins. So there is “lazy loading” to solve this. “lazy”.nvim has many features about lazy loading.&lt;/p&gt;

&lt;p&gt;For example, &lt;a href="https://github.com/nvim-telescope/telescope.nvim" rel="noopener noreferrer"&gt;telescope.nvim&lt;/a&gt;, that is also one of the most popular plugins, has a note in README that describes the way to use with lazy.nvim.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"nvim-telescope/telescope.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-lua/plenary.nvim"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code means that it should install telescope.nvim from GitHub and add a dependency to plenary.nvim. With this, Neovim loads plugins at the startup time without lazy loading.&lt;/p&gt;

&lt;p&gt;If you want to load plugins lazily, you need to specify chances to load them. There are some ways to do this, so I illustrate one way below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"nvim-telescope/telescope.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Telescope"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-lua/plenary.nvim"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Neovim doesn't load telescope.nvim at its startup but loads as soon as you call &lt;code&gt;:Telescope&lt;/code&gt; command at the first time, such as &lt;code&gt;:Telescope find_files&lt;/code&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  When Neovim loads dependencies in lazy loading?
&lt;/h2&gt;

&lt;p&gt;The example above shows that telescope.nvim is loaded after you call &lt;code&gt;:Telescope&lt;/code&gt; command. Then, when plenary.nvim, that telescope.nvim depends on, have been loaded?&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;The answer is “the time Neovim started at”. It is ideal that minimum plugins are loaded in startup, and others are loaded when they are needed. But &lt;code&gt;dependencies&lt;/code&gt; option interferes with it.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;🔔 Note: The following is an addition.&lt;/p&gt;

&lt;p&gt;Sorry. This sentence above have misunderstanding about &lt;code&gt;dependencies&lt;/code&gt;. Plugins in &lt;code&gt;dependencies&lt;/code&gt; are not loaded in Neovim startup. lazy.nvim makes them (such as plenary.nvim) be loaded just before the dependent plugin (telescope.nvim).&lt;/p&gt;

&lt;p&gt;🔔 End of addition.&lt;/p&gt;

&lt;p&gt;You can write settings below to load plenary.nvim relevantly to telescope.nvim.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-telescope/telescope.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Telescope"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-lua/plenary.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;lazy = true&lt;/code&gt; means that you set no chance to load the plugin explicitly, but it should be loaded as soon as it become needed. lazy.nvim detects the plugin to be needed when it does &lt;code&gt;require "plenary"&lt;/code&gt;.&lt;/p&gt;

&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;This works with modules placed deeper, such as &lt;code&gt;require "plenary.log"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This logic is achieved by hacking &lt;code&gt;package.loaders&lt;/code&gt; in Lua core. I cannot write here the detail because it's lengthy.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;That is, lazy.nvim works as below when &lt;code&gt;:Telescope find_files&lt;/code&gt;.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You type &lt;code&gt;:Telescope find_files&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads telescope.nvim.&lt;/li&gt;
&lt;li&gt;It reaches &lt;code&gt;require "plenary.***"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads plenary.nvim.&lt;/li&gt;
&lt;li&gt;It continues the process and shows UI for &lt;code&gt;:Telescope find_files&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  We need “dependencies”?
&lt;/h2&gt;

&lt;p&gt;I think no. It is meaningless that defines dependencies because lazy.nvim loads plugins automatically when they become needed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"nvim-telescope/telescope.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Telescope"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="n"&gt;dependencies&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-lua/plenary.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You even think this code above works good, but this is wrong. You may think it loads when the plugin become needed (when it sees &lt;code&gt;require "plenary.***"&lt;/code&gt;). In fact, lazy.nvim loads plenary.nvim &lt;em&gt;before&lt;/em&gt; telescope.nvim.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You type &lt;code&gt;:Telescope find_files&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads plenary.nvim because it is in &lt;code&gt;dependencies&lt;/code&gt;. It is not loaded in Neovim startup because of &lt;code&gt;lazy = true&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads telescope.nvim.&lt;/li&gt;
&lt;li&gt;It continues the process and show windows for &lt;code&gt;:Telecope find_files&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Yes, this may be difficult to understand. Surely it loads plenary.nvim not in startup. But I want to load it more lazily.&lt;/p&gt;

&lt;p&gt;🔔 Note: The following is an addition.&lt;/p&gt;

&lt;p&gt;This section below is based on &lt;a href="https://lazy.folke.io/developers" rel="noopener noreferrer"&gt;this page&lt;/a&gt;. But this is not for general users but for plugin developers writing &lt;a href="https://lazy.folke.io/packages" rel="noopener noreferrer"&gt;package spec&lt;/a&gt;, so I've commented out it.&lt;/p&gt;

&lt;p&gt;🔔 End of addition.&lt;/p&gt;

&lt;blockquote&gt;
&lt;h2&gt;
  
  
  Official doc also says “Don't use dependencies”
&lt;/h2&gt;

&lt;p&gt;This is not a special technique. The document of lazy.nvim also says that.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;a href="https://lazy.folke.io/developers" rel="noopener noreferrer"&gt;🔥 Developers | lazy.nvim&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Only use dependencies if a plugin needs the dep to be installed &lt;strong&gt;AND&lt;/strong&gt; loaded. Lua plugins/libraries are automatically loaded when they are &lt;code&gt;require()&lt;/code&gt;d, so they don't need to be in dependencies.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It is not easy to find out that &lt;em&gt;“if a plugin needs the dep to be installed AND loaded”&lt;/em&gt;. An example for this is the case when there is an initialization script in &lt;code&gt;plugin&lt;/code&gt; directory of the plugin, and the initialization process is needed by the dependent plugin to work.&lt;/p&gt;

&lt;p&gt;……is this difficult? Then I say again in other words.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definitely, there is no such plugin written with Lua. So you DON'T need to use &lt;code&gt;dependencies&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Why plugin authors/users still use &lt;code&gt;dependencies&lt;/code&gt;?
&lt;/h2&gt;

&lt;p&gt;Even so, some expert users or many popular plugins such as telescope.nvim uses &lt;code&gt;dependencies&lt;/code&gt; in README or their codes. Why?&lt;/p&gt;

&lt;h3&gt;
  
  
  To write “dependencies” (literally)
&lt;/h3&gt;

&lt;p&gt;The &lt;code&gt;dependencies&lt;/code&gt; option is the only one that users can describe plugins' dependency in lazy.nvim. So some expert users (&lt;a href="https://github.com/ayamir/nvimdots/blob/6c1933580ed297cdcfc2094abb815cbb1473e996/lua/modules/plugins/editor.lua#L109" rel="noopener noreferrer"&gt;ayamir/nvimdots&lt;/a&gt;, for example) uses &lt;code&gt;dependencies&lt;/code&gt; even if they know warnings from the official lazy.nvim document.&lt;/p&gt;

&lt;h3&gt;
  
  
  To reduce inquiries
&lt;/h3&gt;

&lt;p&gt;Lazy loading is so difficult, basically. Many inquiries that say &lt;em&gt;I can't see this plugin to be loaded&lt;/em&gt; are caused by lazy loading.&lt;/p&gt;

&lt;p&gt;README should have a config that everyone can work with it. The &lt;code&gt;dependencies&lt;/code&gt; option in it can make even newbie users load all plugins certainly.&lt;/p&gt;

&lt;h3&gt;
  
  
  For Vim Script plugins
&lt;/h3&gt;

&lt;p&gt;lazy.nvim's automatic loading feature (&lt;code&gt;lazy = true&lt;/code&gt;) can work only with plugins written with Lua. You should use &lt;code&gt;dependencies&lt;/code&gt; option for ones written with Vim Script.&lt;/p&gt;

&lt;h3&gt;
  
  
  Really needed by the plugin
&lt;/h3&gt;

&lt;p&gt;This is the case &lt;em&gt;“if a plugin needs the dep to be installed AND loaded”&lt;/em&gt; mentioned above. This is an extremely rare pattern.&lt;/p&gt;

&lt;p&gt;Even if you need an initialization for the dependency, you can write configs below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"foo/bar.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Bar"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"hoge/fuga.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose bar.nvim has a code like &lt;code&gt;require "fuga"&lt;/code&gt; in it. Then it will work as below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You type &lt;code&gt;:Bar&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads bar.nvim.&lt;/li&gt;
&lt;li&gt;It reaches &lt;code&gt;require "fuga"&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads fuga.nvim.&lt;/li&gt;
&lt;li&gt;It calls &lt;code&gt;require("fuga").setup {}&lt;/code&gt;. This is an effect by &lt;code&gt;opts&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;require "fuga"&lt;/code&gt; works well, then it continues &lt;code&gt;:Bar&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The initialization for fuga.nvim is properly executed even in such cases. If still you need &lt;code&gt;dependencies&lt;/code&gt;, it is the case when you need &lt;code&gt;require("fuga").setup {}&lt;/code&gt; to be executed &lt;em&gt;before&lt;/em&gt; it reaches &lt;code&gt;require "fuga"&lt;/code&gt; in bar.nvim. You usually don't want to create such “dependencies”.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some complex examples with popular plugins
&lt;/h2&gt;

&lt;p&gt;As you know, lazy loading is too complex to understand. Here I illustrate some examples.&lt;/p&gt;

&lt;h3&gt;
  
  
  telescope.nvim extensions
&lt;/h3&gt;

&lt;p&gt;Many telescope.nvim users are sure to use extensions. For example, you can write configs with &lt;a href="https://github.com/nvim-telescope/telescope-project.nvim" rel="noopener noreferrer"&gt;telescope-project.nvim&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-telescope/telescope-project.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"nvim-lua/plenary.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;

&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"nvim-telescope/telescope.nvim"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;cmd&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"Telescope"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;extensions&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="n"&gt;project&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;theme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"dropdown"&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code works as below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You type &lt;code&gt;:Telescope project&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads telescope.nvim.&lt;/li&gt;
&lt;li&gt;It does &lt;code&gt;require("telescope').setup { extensions = { …… } }&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;It does &lt;code&gt;require("telescope").load_extension "project"&lt;/code&gt; (&lt;a href="https://github.com/nvim-telescope/telescope.nvim/blob/5972437de807c3bc101565175da66a1aa4f8707a/lua/telescope/command.lua#L192-L201" rel="noopener noreferrer"&gt;here&lt;/a&gt;) because a picker named “project” has not been loaded.&lt;/li&gt;
&lt;li&gt;It does &lt;code&gt;require("telescope._extensions.project")&lt;/code&gt; (&lt;a href="https://github.com/nvim-telescope/telescope.nvim/blob/5972437de807c3bc101565175da66a1aa4f8707a/lua/telescope/_extensions/init.lua#L7-L13" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;lazy.nvim loads telescope-project.nvim.&lt;/li&gt;
&lt;li&gt;lazy.nvim does the initialization for telescope-project.nvim (&lt;code&gt;require("telescope._extensions.project").setup { theme = "dropdown" }&lt;/code&gt;) (&lt;a href="https://github.com/nvim-telescope/telescope.nvim/blob/5972437de807c3bc101565175da66a1aa4f8707a/lua/telescope/_extensions/init.lua#L19-L21" rel="noopener noreferrer"&gt;here&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;It continues the process for &lt;code&gt;:Telescope project&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Hmm…… It's so complex.&lt;/p&gt;

&lt;h3&gt;
  
  
  nvim-cmp and its sources
&lt;/h3&gt;

&lt;p&gt;You should use many source plugins to use &lt;a href="https://github.com/hrsh7th/nvim-cmp" rel="noopener noreferrer"&gt;nvim-cmp&lt;/a&gt; effectively. The orders to load them lazily are difficult a bit to understand.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight lua"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"hrsh7th/cmp-buffer"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;event&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"InsertEnter"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"mtoohey31/cmp-fish"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ft&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="s2"&gt;"fish"&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="s2"&gt;"hrsh7th/nvim-cmp"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;lazy&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;opts&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="err"&gt;……&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
&lt;span class="p"&gt;},&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code above is a config to load nvim-cmp and its sources lazily. When you start the Insert mode at the first time, lazy.nvim works as below.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You start to input any character.&lt;/li&gt;
&lt;li&gt;Neovim invokes &lt;a href="https://neovim.io/doc/user/autocmd.html#InsertEnter" rel="noopener noreferrer"&gt;InsertEnter&lt;/a&gt; event.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads cmp-buffer.&lt;/li&gt;
&lt;li&gt;It sources &lt;code&gt;after/plugin/cmp_buffer.lua&lt;/code&gt; in cmp-buffer.&lt;/li&gt;
&lt;li&gt;It reaches &lt;code&gt;require("cmp").register_source(……)&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads nvim-cmp.&lt;/li&gt;
&lt;li&gt;lazy.nvim does the initialization of nvim-cmp: &lt;code&gt;require("cmp").setup { …… }&lt;/code&gt;. This is an effect by &lt;code&gt;opts&lt;/code&gt; option.&lt;/li&gt;
&lt;li&gt;It continues the process for &lt;code&gt;require("cmp").register_source()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Now nvim-cmp does the code completion as its normal way.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This config also adds &lt;a href="https://github.com/mtoohey31/cmp-fish" rel="noopener noreferrer"&gt;cmp-fish&lt;/a&gt;. This source is needed only in fish scripts, so it is delayed to be loaded until you open fish scripts.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;You open a fish script.&lt;/li&gt;
&lt;li&gt;Neovim invokes &lt;a href="https://neovim.io/doc/user/autocmd.html#FileType" rel="noopener noreferrer"&gt;FileType&lt;/a&gt; event.&lt;/li&gt;
&lt;li&gt;lazy.nvim loads cmp-fish.&lt;/li&gt;
&lt;li&gt;(This and latter ones are almost the same as cmp-buffer)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Complex, but easier than the case with telescope.nvim extensions?&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This article explained the way lazy.nvim deals with &lt;code&gt;dependencies&lt;/code&gt; option and correct places to use it. Lazy loading is a challenging matter in using Neovim plugins. You can learn Neovim's startup mechanism deeper when you are hacking with lazy.nvim.&lt;/p&gt;

&lt;h3&gt;
  
  
  Bonus Content
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;My GitHub account → &lt;a href="https://github.com/delphinus" rel="noopener noreferrer"&gt;@delphinus&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;I'm mainly developing a telescope.nvim extension: &lt;a href="https://github.com/nvim-telescope/telescope-frecency.nvim" rel="noopener noreferrer"&gt;telescope-frecency.nvim&lt;/a&gt;. You should use this if you are searching a cleverer picker to find files in history than &lt;code&gt;:Telescope oldfiles&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;This is an English version of my article written in Japanese: &lt;a href="https://qiita.com/delphinus/items/d07994f29550764bd8bc" rel="noopener noreferrer"&gt;lazy.nvim で dependencies を使うのはやめよう #neovim - Qiita&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>neovim</category>
    </item>
  </channel>
</rss>
