Neovim插件管理Packer切换为Lazy
今天本想解决Neovim自动化配置脚本编写问题,意外得知Packer已经不再维护,其官方仓库
packer.nvim
写到:
{% note info %} This repository is currently unmaintained. For the time being (as of August, 2023), it is recommended to use one of the following plugin managers instead:
- lazy.nvim : Most stable and maintained plugin manager for Nvim.
- pckr.nvim : Spiritual successor of packer.nvim. Functional but not as stable as lazy.nvim. {% endnote %}
这个消息很突然,但是之前lazy.nvim更加优秀,同时也得到了packer.nvim作者的认可,具体原因不得而知,既然packer.nvim不再维护,同时作者给了两个替代方案,显然更加稳定的lazy.nvim就是一个可靠的选择。
切换流程
- 册除
packer.nvim的编译目录~/.config/nvim/plugins和由packer.nvim安装的插件.
- 删除
packer.nvim的配置文件~/.config/nvim/lua/plg/plugin.lua.
| |
- 同时新建
lazy.nvim的配置文件lazy-init.lua
| |
{% note info %}
注意: 官方网站还给出了另一个方法,就是将lazy-init.lua放在目录~/.config/nvim中,同时插件配置文件单独建立,然后再调用,但是本着lazy的原则,我还是更愿意一个文件解决问题,因为插件也不是多的放不下,文件越少越方便管理。
{% endnote %}
- 建立
~/.config/nvim/init.vim配置文件
- 先设置不引入插件,写入
| |
启动nvim,然后插件就会自动开始安装了。
- 启动各插件
| |
{% note warning %}
选择建立~/.config/nvim/init.vim,因为有些vim的插件还没有完全使用lua重写,比如fcitx5在不同模式下自动切换的这段代码就必须写在init.vim文件中才得,这是当前一个最好的选择。
{% endnote %}
Lazy 使用方法
Plugins are managed with the :Lazy command.
Open the help with <?> to see all the key mappings.
You can press <CR> on a plugin to show its details. Most properties
can be hovered with <K> to open links, help files, readmes,
git commits and git issues.
Lazy can automatically check for updates in the background. This feature
can be enabled with config.checker.enabled = true.
Any operation can be started from the UI, with a sub command or an API function:
| Command | Lua | Description |
|---|---|---|
:Lazy build {plugins} | require("lazy").build(opts) | Rebuild a plugin |
:Lazy check [plugins] | require("lazy").check(opts?) | Check for updates and show the log (git fetch) |
:Lazy clean [plugins] | require("lazy").clean(opts?) | Clean plugins that are no longer needed |
:Lazy clear | require("lazy").clear() | Clear finished tasks |
:Lazy debug | require("lazy").debug() | Show debug information |
:Lazy health | require("lazy").health() | Run :checkhealth lazy |
:Lazy help | require("lazy").help() | Toggle this help page |
:Lazy home | require("lazy").home() | Go back to plugin list |
:Lazy install [plugins] | require("lazy").install(opts?) | Install missing plugins |
:Lazy load {plugins} | require("lazy").load(opts) | Load a plugin that has not been loaded yet. Similar to :packadd. Like :Lazy load foo.nvim. Use :Lazy! load to skip cond checks. |
:Lazy log [plugins] | require("lazy").log(opts?) | Show recent updates |
:Lazy profile | require("lazy").profile() | Show detailed profiling |
:Lazy reload {plugins} | require("lazy").reload(opts) | Reload a plugin (experimental!!) |
:Lazy restore [plugins] | require("lazy").restore(opts?) | Updates all plugins to the state in the lockfile. For a single plugin: restore it to the state in the lockfile or to a given commit under the cursor |
:Lazy sync [plugins] | require("lazy").sync(opts?) | Run install, clean and update |
:Lazy update [plugins] | require("lazy").update(opts?) | Update plugins. This will also update the lockfile |
Any command can have a bang to make the command wait till it finished. For example, if you want to sync lazy from the cmdline, you can use:
| |
opts is a table with the following key-values:
- wait: when true, then the call will wait till the operation completed
- show: when false, the UI will not be shown
- plugins: a list of plugin names to run the operation on
- concurrency: limit the
numberof concurrently running tasks
Stats API (require("lazy").stats()):
| |
lazy.nvim provides a statusline component that you can use to show the number of pending updates.
Make sure to enable config.checker.enabled = true to make this work.