mirror of
https://github.com/folke/lazy.nvim.git
synced 2025-04-18 20:36:45 +00:00
feat: added :Lazy load foobar.nvim
to load a plugin
This commit is contained in:
parent
8a0da3b27e
commit
2dd6230018
4 changed files with 52 additions and 21 deletions
|
@ -83,9 +83,7 @@ function M.commands()
|
|||
for _, mode in ipairs(modes) do
|
||||
if not mode.plugin and commands[mode.name] then
|
||||
lines[#lines + 1] = {
|
||||
("`:Lazy %s`"):format(mode.name) .. " or " .. ("`:Lazy%s`"):format(
|
||||
mode.name:sub(1, 1):upper() .. mode.name:sub(2)
|
||||
),
|
||||
("`:Lazy %s`"):format(mode.name),
|
||||
([[`require("lazy").%s()`]]):format(mode.name),
|
||||
mode.key and ("`<%s>`"):format(mode.key) or "",
|
||||
mode.desc,
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
local View = require("lazy.view")
|
||||
local Manage = require("lazy.manage")
|
||||
local Util = require("lazy.util")
|
||||
local Config = require("lazy.core.config")
|
||||
|
||||
local M = {}
|
||||
|
||||
|
@ -60,20 +61,46 @@ M.commands = {
|
|||
restore = function(plugins)
|
||||
Manage.update({ clear = true, lockfile = true, mode = "restore", plugins = plugins })
|
||||
end,
|
||||
load = function(plugins)
|
||||
require("lazy.core.loader").load(plugins, { cmd = "LazyLoad" })
|
||||
end,
|
||||
}
|
||||
|
||||
function M.complete_unloaded(prefix)
|
||||
local plugins = {}
|
||||
for name, plugin in pairs(Config.plugins) do
|
||||
if not plugin._.loaded then
|
||||
plugins[#plugins + 1] = name
|
||||
end
|
||||
end
|
||||
table.sort(plugins)
|
||||
---@param key string
|
||||
return vim.tbl_filter(function(key)
|
||||
return key:find(prefix) == 1
|
||||
end, plugins)
|
||||
end
|
||||
|
||||
function M.setup()
|
||||
vim.api.nvim_create_user_command("Lazy", function(args)
|
||||
M.cmd(vim.trim(args.args or ""))
|
||||
vim.api.nvim_create_user_command("Lazy", function(cmd)
|
||||
local args = vim.split(vim.trim(cmd.args or ""), " ")
|
||||
local name = args[1]
|
||||
table.remove(args, 1)
|
||||
M.cmd(name, #args > 0 and args or nil)
|
||||
end, {
|
||||
nargs = "?",
|
||||
desc = "Lazy",
|
||||
complete = function(_, line)
|
||||
---@type string?
|
||||
local prefix = line:match("^%s*Lazy load (%w*)")
|
||||
if prefix then
|
||||
return M.complete_unloaded(prefix)
|
||||
end
|
||||
|
||||
if line:match("^%s*Lazy %w+ ") then
|
||||
return {}
|
||||
end
|
||||
|
||||
local prefix = line:match("^%s*Lazy (%w*)") or ""
|
||||
prefix = line:match("^%s*Lazy (%w*)") or ""
|
||||
|
||||
---@param key string
|
||||
return vim.tbl_filter(function(key)
|
||||
|
|
|
@ -17,6 +17,11 @@ M.modes = {
|
|||
{ name = "debug", key = "D", desc = "Show debug information", toggle = true },
|
||||
{ name = "help", key = "?", desc = "Toggle this help page", toggle = true },
|
||||
{ name = "clear", desc = "Clear finished tasks", hide = true },
|
||||
{
|
||||
name = "load",
|
||||
desc = "Load a plugin that has not been loaded yet. Similar to `:packadd`. Like `:Lazy load foo.nvim`",
|
||||
hide = true,
|
||||
},
|
||||
|
||||
{ plugin = true, name = "update", key = "u", desc = "Update this plugin. This will also update the lockfile" },
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue