lazy.nvimは、Neovim用の最新のプラグインマネージャーです。
README.md
lazy-lock.json
次の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)
table
string
table:プラグイン仕様のリスト
string: プラグイン仕様を含む Lua モジュール名。プラグインの構造化を参照してください。
-- 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
string
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,
},
}
{
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は、次のキー値を持つテーブルです。
number
ダッシュボードにプラグインの数を表示する場合は、 このシンプルな API では、次のことを行います。
local plugins = require("lazy").stats().count
lazy.nvim には、保留中の更新の数を表示するために使用できるステータスラインコンポーネントが用意されています。 これを機能させるようにしてください。
config.checker.enabled = true
require("lualine").setup({
sections = {
lualine_x = {
{
require("lazy.status").updates,
cond = require("lazy.status").has_updates,
color = { fg = "#ff9e64" },
},
},
},
})
次のユーザーイベントがトリガーされます。
LazyDone
VimEnter
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
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
See an overview of active lazy-loading handlers and what's in the module cache
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:
init()
lazy=false
/plugin
/ftdetect
/after
/plugin
/ftdetect
/after)
/after/plugin
/after
Files from runtime directories are always sourced in alphabetical order.
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:
:Lazy
Example:
~/.config/nvim/init.lua
require("lazy").setup("plugins")
~/.config/nvim/lua/plugins.luaor (this file is optional)
~/.config/nvim/lua/plugins/init.lua
return {
"folke/neodev.nvim",
"folke/which-key.nvim",
{ "folke/neoconf.nvim", cmd = "Neoconf" },
}
~/.config/nvim/lua/plugins/*.lua
For a real-life example, you can check my personal dots:
config.lazy
setup
init
requires
dependencies
as
name
opt
lazy
run
build
lock
pin
disable=true
enabled = false
tag='*'
version="*"
after
dependencies
wants
dependencies
moduleis auto-loaded. No need to specify
keysspec 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