lazy.nvim - 💤 ネオビム用の最新のプラグインマネージャー

(💤 A modern plugin manager for Neovim)

Created at: 2022-11-21 05:36:02
Language: Lua
License: Apache-2.0

💤 レイジー.nヴィム

lazy.nvimは、Neovim用の最新のプラグインマネージャーです。

画像

顔立ち

  • 📦強力なUIですべてのNeovimプラグインを管理します
  • 🚀luaモジュールの自動キャッシュとバイトコードコンパイルによる高速起動時間
  • 💾浅いクローンではなく部分的なクローン
  • 🔌luaモジュールの自動遅延読み込みと、イベント、コマンド、ファイルタイプ、およびキーマッピングの遅延読み込み
  • Neovimを起動する前に不足しているプラグインを自動的にインストールし、すぐに使用を開始できるようにします
  • 💪パフォーマンス向上のための非同期実行
  • 🛠️プラグインを手動でコンパイルする必要はありません
  • 🧪依存関係の正しい順序付け
  • 📁複数のファイルで構成可能
  • 📚vimdocsを持たないプラグインのファイル内の見出しのヘルプタグを生成します
    README.md
  • 💻ローカルプラグインを使用するための開発オプションとパターン
  • 📊パフォーマンスを最適化するためのプロファイリングツール
  • 🔒インストールされたプラグインを追跡するためのロックファイル
    lazy-lock.json
  • 🔎更新プログラムを自動的に確認する
  • 📋コミット、ブランチ、タグ、バージョン、および完全なSemverサポート
  • 📈保留中の更新の数を確認するステータスラインコンポーネント
  • 🎨配色を自動的に遅延読み込みする

⚡️必要条件

  • Neovim > = 0.8.0 (LuaJIT でビルドする必要があります))
  • Git > = 2.19.0 (部分的なクローンのサポート用)
  • オタクフォント(オプション)

📦取り付け

次のLuaコードをブートストラップlazy.nvimに追加できます

init.lua

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",
    "--single-branch",
    "https://github.com/folke/lazy.nvim.git",
    lazypath,
  })
end
vim.opt.runtimepath:prepend(lazypath)

次のステップは、あなたの一番上にlazy.nvimを追加することです

init.lua

require("lazy").setup(plugins, opts)
-- example using a list of specs with the default options
vim.g.mapleader = " " -- make sure to set `mapleader` before lazy so your mappings are correct

require("lazy").setup({
  "folke/which-key.nvim",
  { "folke/neoconf.nvim", cmd = "Neoconf" },
  "folke/neodev.nvim",
})

ℹ️インストール後に実行することをお勧めします

:checkhealth lazy

🔌プラグイン仕様

財産 種類 形容
[1]
string?
短いプラグインの URL。を使用して拡張されます
config.git.url_format
ディレクトリ
string?
ローカルプラグインを指すディレクトリ
リンク
string?
プラグインがホストされているカスタム git URL
名前
string?
ローカルプラグインディレクトリおよび表示名として使用されるプラグインのカスタム名
デベロップメント
boolean?
の場合、代わりにローカルプラグインディレクトリが使用されます。見る
true
config.dev
怠惰
boolean?
の場合、プラグインは必要な場合にのみロードされます。遅延読み込みされたプラグインは、Luaモジュールが 、または遅延読み込みハンドラーの1つがトリガーされたときに自動的に読み込まれます。
true
required
有効
boolean?
又は
fun():boolean
の場合、または がfalseを返す場合、このプラグインは使用されません。
false
function
依存 関係
LazySpec[]
プラグインのロード時にロードする必要があるプラグイン仕様のリスト。依存関係は、特に指定がない限り、常に遅延ロードされます
初期化
fun(LazyPlugin)
init
関数は常に起動時に実行されます
設定
fun(LazyPlugin)
または
true
table
config
プラグインが読み込まれるときに実行されます。また、 に設定したり、 を渡したりすることもできます。
true
table
require("plugin").setup(opts)
建てる
fun(LazyPlugin)
またはビルドコマンドのリスト
string
build
プラグインがインストールまたは更新されたときに実行されます。文字列の場合は、シェルコマンドとして実行されます。接頭辞が付いているのは Neovim コマンドです。複数のビルドコマンドを実行するリストを指定することもできます
:
string?
リポジトリのブランチ
タグ
string?
リポジトリのタグ
犯す
string?
リポジトリのコミット
バージョン
string?
リポジトリから使用するバージョン。完全なセンバー範囲がサポートされています
ピン
boolean?
の場合、このプラグインはアップデートに含まれません
true
出来事
string?
又は
string[]
イベントの遅延読み込み
ティッカー
string?
又は
string[]
コマンドの遅延ロード
フィート
string?
又は
string[]
ファイルタイプの遅延ロード
キー
string?
または
string[]
LazyKeys[]
キーマッピングの遅延ロード
モジュール
false?
このLuaモジュールがどこかで必要なときに自動的にロードしないでください

遅延読み込み

lazy.nvimは自動的にLuaモジュールを遅延ロードするので、 プラグイン仕様のどこにでも指定します。これは、 遅延ロードされたプラグインと、 プラグインのモジュールの場合、プラグインは期待どおりにオンデマンドでロードされます。

module=...
A
B
A
A

特定のプラグインでこの動作を望まない場合は、で指定できます。 その後、を使用してプラグインを手動でロードできます。

module=false
:Lazy load foobar.nvim

カラースキームプラグインは、で構成できます。プラグインは自動的に読み込まれます するとき.

lazy=true
colorscheme foobar

デフォルトですべてのプラグインを遅延ロードするようにlazy.nvimを構成できます。

config.defaults.lazy = true

さらに、イベントコマンドファイルタイプキーマッピングを遅延ロードすることもできます。

プラグインは、次のいずれかが次の場合に遅延ロードされます。

true

  • プラグインは仕様の依存関係としてのみ存在します
  • 、、またはキーがあります
    event
    cmd
    ft
    keys
  • config.defaults.lazy == true

⌨️遅延キーマッピング

このプロパティは、単純な通常モード マッピングの場合は or にすることも、 は、次のキーと値のペアを持つテーブルになります。

keys
string
string[]
LazyKeys

  • [1]: () LHS (必須)
    string
  • [2]: () RHS (オプション)
    string|fun()
  • モード: () モード (オプション、デフォルトは "n")
    string|string[]
  • 有効なその他のオプション
    vim.keymap.set

キーマッピングは、初めて実行されるときにプラグインをロードします。

が の場合、実際のマッピングは関数によって作成する必要があります。

[2]
nil
config()

-- Example for neo-tree.nvim
{
  "nvim-neo-tree/neo-tree.nvim",
    keys = {
      { "<leader>ft", "<cmd>Neotree toggle<cr>", desc = "NeoTree" },
    },
    config = function()
      require("neo-tree").setup()
      end,
}

バージョン管理

プラグインの特定のリビジョンをインストールする場合は、、を使用できます。

commit
tag
branch
version

このプロパティは、Semver の範囲をサポートしています。

version

クリックしていくつかの例を見る
  • *
    :最新の安定版(プレリリース版を除く)
  • 1.2.x
    : で始まるバージョン (、など)。
    1.2
    1.2.0
    1.2.3
  • ^1.2.3
    : 、などと互換性があるが、 と互換性がないバージョン 。
    1.2.3
    1.3.0
    1.4.5
    2.0.0
  • ~1.2.3
    : と互換性がありますが、 など、 と互換性があるが、 は互換性がないバージョン 。
    1.2.3
    1.2.4
    1.2.5
    1.3.0
  • >1.2.3
    : 、など、より大きいバージョン。
    1.2.3
    1.3.0
    1.4.5
  • >=1.2.3
    : 、、など、 以上の任意のバージョン。
    1.2.3
    1.2.3
    1.3.0
    1.4.5
  • <1.2.3
    : より小さいバージョン , など。
    1.2.3
    1.1.0
    1.0.5
  • <=1.2.3
    : 、、などの 以下のバージョン
    1.2.3
    1.2.3
    1.1.0
    1.0.5

最新の安定版をインストールするように設定できます Semverをサポートするプラグインのバージョン。

config.defaults.version = "*"

return {
  -- the colorscheme should be available when starting Neovim
  "folke/tokyonight.nvim",

  -- I have a separate config.mappings file where I require which-key.
  -- With lazy the plugin will be automatically loaded when it is required somewhere
  { "folke/which-key.nvim", lazy = true },

  {
    "nvim-neorg/neorg",
    -- lazy-load on filetype
    ft = "norg",
    -- custom config that will be executed when loading the plugin
    config = function()
      require("neorg").setup()
    end,
  },

  -- the above could also be written as
  {
    "nvim-neorg/neorg",
    ft = "norg",
    config = true, -- run require("norg").setup()
  },

  -- or set custom config
  {
    "nvim-neorg/neorg",
    ft = "norg",
    config = { foo = "bar" }, -- run require("norg").setup({foo = "bar"})
  },

  {
    "dstein64/vim-startuptime",
    -- lazy-load on a command
    cmd = "StartupTime",
  },

  {
    "hrsh7th/nvim-cmp",
    -- load cmp on InsertEnter
    event = "InsertEnter",
    -- these dependencies will only be loaded when cmp loads
    -- dependencies are always lazy-loaded unless specified otherwise
    dependencies = {
      "hrsh7th/cmp-nvim-lsp",
      "hrsh7th/cmp-buffer",
    },
    config = function()
      -- ...
    end,
  },

  -- you can use the VeryLazy event for things that can
  -- load later and are not important for the initial UI
  { "stevearc/dressing.nvim", event = "VeryLazy" },

  {
    "cshuaimin/ssr.nvim",
    -- init is always executed during startup, but doesn't load the plugin yet.
    init = function()
      vim.keymap.set({ "n", "x" }, "<leader>cR", function()
        -- this require will automatically load the plugin
        require("ssr").open()
      end, { desc = "Structural Replace" })
    end,
  },

  {
    "monaqa/dial.nvim",
    -- lazy-load on keys
    -- mode is `n` by default. For more advanced options, check the section on key mappings
    keys = { "<C-a>", { "<C-x>", mode = "n" } },
  },

  -- local plugins need to be explicitly configured with dir
  { dir = "~/projects/secret.nvim" },

  -- you can use a custom url to fetch a plugin
  { url = "git@github.com:folke/noice.nvim.git" },

  -- local plugins can also be configure with the dev option.
  -- This will use {config.dev.path}/noice.nvim/ instead of fetching it from Github
  -- With the dev option, you can easily switch between the local and installed version of a plugin
  { "folke/noice.nvim", dev = true },
}

⚙️構成

lazy.nvim には、次のデフォルトが付属しています。

{
  root = vim.fn.stdpath("data") .. "/lazy", -- directory where plugins will be installed
  defaults = {
    lazy = false, -- should plugins be lazy-loaded?
    version = nil,
    -- version = "*", -- enable this to try installing the latest stable versions of plugins
  },
  lockfile = vim.fn.stdpath("config") .. "/lazy-lock.json", -- lockfile generated after running update.
  concurrency = nil, ---@type number limit the maximum amount of concurrent tasks
  git = {
    -- defaults for the `Lazy log` command
    -- log = { "-10" }, -- show the last 10 commits
    log = { "--since=3 days ago" }, -- show commits from the last 3 days
    timeout = 120, -- kill processes that take more than 2 minutes
    url_format = "https://github.com/%s.git",
  },
  dev = {
    -- directory where you store your local plugin projects
    path = "~/projects",
    ---@type string[] plugins that match these patterns will use your local versions instead of being fetched from GitHub
    patterns = {}, -- For example {"folke"}
  },
  install = {
    -- install missing plugins on startup. This doesn't increase startup time.
    missing = true,
    -- try to load one of these colorschemes when starting an installation during startup
    colorscheme = { "habamax" },
  },
  ui = {
    -- a number <1 is a percentage., >1 is a fixed size
    size = { width = 0.8, height = 0.8 },
    -- The border to use for the UI window. Accepts same border values as |nvim_open_win()|.
    border = "none",
    icons = {
      cmd = "",
      config = "",
      event = "",
      ft = "",
      init = "",
      keys = "",
      plugin = "",
      runtime = "",
      source = "",
      start = "",
      task = "",
    },
    throttle = 20, -- how frequently should the ui process render events
    custom_keys = {
      -- you can define custom key maps here.
      -- To disable one of the defaults, set it to false

      -- open lazygit log
      ["<localleader>l"] = function(plugin)
        require("lazy.util").open_cmd({ "lazygit", "log" }, {
          cwd = plugin.dir,
          terminal = true,
          close_on_exit = true,
          enter = true,
        })
      end,

      -- open a terminal for the plugin dir
      ["<localleader>t"] = function(plugin)
        require("lazy.util").open_cmd({ vim.go.shell }, {
          cwd = plugin.dir,
          terminal = true,
          close_on_exit = true,
          enter = true,
        })
      end,
    },
  },
  diff = {
    -- diff command <d> can be one of:
    -- * browser: opens the github compare view. Note that this is always mapped to <K> as well,
    --   so you can have a different command for diff <d>
    -- * git: will run git diff and open a buffer with filetype git
    -- * terminal_git: will open a pseudo terminal with git diff
    -- * diffview.nvim: will open Diffview to show the diff
    cmd = "git",
  },
  checker = {
    -- automatically check for plugin updates
    enabled = false,
    concurrency = nil, ---@type number? set to 1 to check for updates very slowly
    notify = true, -- get a notification when new updates are found
    frequency = 3600, -- check for updates every hour
  },
  change_detection = {
    -- automatically check for config file changes and reload the ui
    enabled = true,
    notify = true, -- get a notification when changes are found
  },
  performance = {
    cache = {
      enabled = true,
      path = vim.fn.stdpath("cache") .. "/lazy/cache",
      -- Once one of the following events triggers, caching will be disabled.
      -- To cache all modules, set this to `{}`, but that is not recommended.
      -- The default is to disable on:
      --  * VimEnter: not useful to cache anything else beyond startup
      --  * BufReadPre: this will be triggered early when opening a file from the command line directly
      disable_events = { "VimEnter", "BufReadPre" },
    },
    reset_packpath = true, -- reset the package path to improve startup time
    rtp = {
      reset = true, -- reset the runtime path to $VIMRUNTIME and your config directory
      ---@type string[]
      paths = {}, -- add any custom paths here that you want to indluce in the rtp
      ---@type string[] list any plugins you want to disable here
      disabled_plugins = {
        -- "gzip",
        -- "matchit",
        -- "matchparen",
        -- "netrwPlugin",
        -- "tarPlugin",
        -- "tohtml",
        -- "tutor",
        -- "zipPlugin",
      },
    },
  },
  -- lazy can generate helptags from the headings in markdown readme files,
  -- so :help works even for plugins that don't have vim docs.
  -- when the readme opens with :help it will be correctly displayed as markdown
  readme = {
    root = vim.fn.stdpath("state") .. "/lazy/readme",
    files = { "README.md" },
    -- only generate markdown helptags for plugins that dont have docs
    skip_if_doc_exists = true,
  },
}
オタクフォントを使用したくない場合は、アイコンをUnicode記号に置き換えることができます。
{
  ui = {
    icons = {
      cmd = "",
      config = "🛠",
      event = "📅",
      ft = "📂",
      init = "",
      keys = "🗝",
      plugin = "🔌",
      runtime = "💻",
      source = "📄",
      start = "🚀",
      task = "📌",
    },
  },
}

🚀使い

プラグインはコマンドで管理されます。 ヘルプを開くと、すべてのキー マッピングが表示されます。

:Lazy
<?>

プラグインを押すと、その詳細を表示できます。ほとんどのプロパティ にカーソルを合わせると、リンク、ヘルプファイル、readmes、 git のコミットと git の問題。

<CR>
<K>

レイジーはバックグラウンドで更新を自動的にチェックできます。この機能 で有効にすることができます。

config.checker.enabled = true

すべての操作は、サブコマンドまたはAPI関数を使用してUIから開始できます。

命令 ルア 形容
:Lazy check [plugins]
require("lazy").check(opts?)
更新を確認し、ログを表示する(git fetch)
:Lazy clean [plugins]
require("lazy").clean(opts?)
不要になったプラグインをクリーンアップする
:Lazy clear
require("lazy").clear()
完了したタスクをクリアする
:Lazy debug
require("lazy").debug()
デバッグ情報の表示
:Lazy help
require("lazy").help()
このヘルプページを切り替える
:Lazy home
require("lazy").home()
プラグイン一覧に戻る
:Lazy install [plugins]
require("lazy").install(opts?)
不足しているプラグインをインストールする
:Lazy load {plugins}
require("lazy").load(opts)
まだロードされていないプラグインをロードします。に似ています。という感じで
:packadd
:Lazy load foo.nvim
:Lazy log [plugins]
require("lazy").log(opts?)
最近の更新を表示する
:Lazy profile
require("lazy").profile()
詳細なプロファイリングを表示する
:Lazy restore [plugins]
require("lazy").restore(opts?)
すべてのプラグインをロックファイル内の状態に更新します
:Lazy sync [plugins]
require("lazy").sync(opts?)
インストール、クリーンアップ、更新を実行する
:Lazy update [plugins]
require("lazy").update(opts?)
プラグインを更新します。これにより、ロックファイルも更新されます

どのコマンドにも、コマンドが終了するまで待機させるための強打があります。例えば cmdlineから遅延を同期する場合は、次を使用できます。

$ nvim --headless "+Lazy! sync" +qa

opts
は、次のキー値を持つテーブルです。

  • wait: true の場合、呼び出しは操作が完了するまで待機します
  • 表示: false の場合、UI は表示されません。
  • プラグイン: 操作を実行するプラグイン名のリスト
  • 同時実行: 同時に実行されるタスクを制限する
    number

ダッシュボードにプラグインの数を表示する場合は、 このシンプルな API では、次のことを行います。

local plugins = require("lazy").stats().count

lazy.nvim には、保留中の更新の数を表示するために使用できるステータスラインコンポーネントが用意されています。 これを機能させるようにしてください。

config.checker.enabled = true

lualine.nvim の設定例
require("lualine").setup({
  sections = {
    lualine_x = {
      {
        require("lazy.status").updates,
        cond = require("lazy.status").has_updates,
        color = { fg = "#ff9e64" },
      },
    },
  },
})

📆ユーザーイベント

次のユーザーイベントがトリガーされます。

  • LazyDone:怠惰な起動が完了し、設定がロードされたとき
  • レイジーシンク:同期を実行した後
  • レイジーインストール:インストール後
  • レイジーアップデート:アップデート後
  • レイジークリーン:クリーン後
  • レイジーチェック:更新を確認した後
  • レイジーログ:ログを実行した後
  • VeryLazy: triggered after and processing auto commands
    LazyDone
    VimEnter

🔒 Lockfile
lazy-lock.json

After every update, the local lockfile is updated with the installed revisions. It is recommended to have this file under version control.

If you use your Neovim config on multiple machines, using the lockfile, you can ensure that the same version of every plugin is installed.

If you are on another machine, you can do , to update all your plugins to the version from the lockfile.

:Lazy restore

Performance

Great care has been taken to make the startup code () as efficient as possible. During startup, all Lua files used before or are byte-compiled and cached, similar to what impatient.nvim does.

lazy.core
VimEnter
BufReadPre

My config for example loads in about with plugins. I do a lot of lazy-loading though :)

11ms
93

lazy.nvim comes with an advanced profiler to help you improve performance. The profiling view shows you why and how long it took to load your plugins.

:Lazy profile

image

🪲 Debug

See an overview of active lazy-loading handlers and what's in the module cache

image

▶️ Startup Sequence

lazy.nvim does NOT use Neovim packages and even disables plugin loading completely (). It takes over the complete startup sequence for more flexibility and better performance.

vim.go.loadplugins = false

In practice this means that step 10 of Neovim Initialization is done by Lazy:

  1. all the plugins' functions are executed
    init()
  2. all plugins with are loaded. This includes sourcing and files. ( will not be sourced yet)
    lazy=false
    /plugin
    /ftdetect
    /after
  3. all files from and directories in you rtp are sourced (excluding
    /plugin
    /ftdetect
    /after
    )
  4. all files are sourced (this inludes from plugins)
    /after/plugin
    /after

Files from runtime directories are always sourced in alphabetical order.

📂 Structuring Your Plugins

Some users may want to split their plugin specs in multiple files. Instead of passing a spec table to , you can use a Lua module. The specs from the module and any sub-modules will be merged together in the final spec, so it is not needed to add calls in your main plugin file to the other files.

setup()
require

The benefits of using this approach:

  • simple to add new plugin specs. Just create a new file in your plugins module.
  • allows for caching of all your plugin specs. This becomes important if you have a lot of smaller plugin specs.
  • spec changes will automatically be reloaded when they're updated, so the UI is always up to date
    :Lazy

Example:

  • ~/.config/nvim/init.lua
require("lazy").setup("plugins")
  • ~/.config/nvim/lua/plugins.lua
    or (this file is optional)
    ~/.config/nvim/lua/plugins/init.lua
return {
  "folke/neodev.nvim",
    "folke/which-key.nvim",
    { "folke/neoconf.nvim", cmd = "Neoconf" },
}
  • any lua file in will be automatically merged in the main plugin spec
    ~/.config/nvim/lua/plugins/*.lua

For a real-life example, you can check my personal dots:

📦 Migration Guide

packer.nvim

  • setup
    ➡️
    init
  • requires
    ➡️
    dependencies
  • as
    ➡️
    name
  • opt
    ➡️
    lazy
  • run
    ➡️
    build
  • lock
    ➡️
    pin
  • disable=true
    ➡️
    enabled = false
  • tag='*'
    ➡️
    version="*"
  • after
    ℹ️ not needed for most use-cases. Use otherwise.
    dependencies
  • wants
    ℹ️ not needed for most use-cases. Use otherwise.
    dependencies
  • module
    is auto-loaded. No need to specify
  • keys
    spec is different

パッカーを使用すると、依存関係を管理するために使用できます。 怠惰では、これはほとんどのlua依存関係には必要ありません。通常のプラグインと同じようにインストールできます (でも)があり、他のプラグインが必要とするときにロードされます。 キーを使用して、必要なプラグインをそれらを必要とするプラグインとグループ化できます。 追加されたプラグインは、プラグインがロードされるときに常に遅延ロードされ、ロードされます。

wants
requires
after
lazy=true
dependencies
dependencies

パク・ンヴィム

  • as
    ➡️
    name
  • opt
    ➡️
    lazy
  • run
    ➡️
    build

アンインストール

lazy.nvimをアンインストールするには、次のファイルとディレクトリを削除する必要があります。

  • データ:
    ~/.local/share/nvim/lazy
  • 状態:
    ~/.local/state/nvim/lazy
  • ロックファイル:
    ~/.config/nvim/lazy-lock.json

環境変数を変更した場合は、パスが異なる場合があります。

XDG

📦Luaの他のネオビムプラグインマネージャー