惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
I
InfoQ
人人都是产品经理
人人都是产品经理
博客园 - 三生石上(FineUI控件)
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
SegmentFault 最新的问题
美团技术团队
小众软件
小众软件
Blog — PlanetScale
Blog — PlanetScale
Jina AI
Jina AI
aimingoo的专栏
aimingoo的专栏
H
Help Net Security
Last Week in AI
Last Week in AI
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
L
LangChain Blog
云风的 BLOG
云风的 BLOG
Martin Fowler
Martin Fowler
宝玉的分享
宝玉的分享
G
Google Developers Blog
博客园 - 叶小钗
博客园 - Franky

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
How to Use LuaRocks Package in Neovim
2024-12-12 · via jdhao's digital space

Although neovim has built a lot of modules to ease the use of Lua, sometimes we may still want to use packages from LuaRocks. In this post, I would like to share how you can install a package from LuaRocks and use it in nvim.

lazy.nvim#

The first way is to use lazy.nvim to install LuaRocks package. We need to

  • install LuaRocks: brew install luarocks
  • install lua 5.1: brew install --force lua@5.1 (--force is needed because otherwise brew will warn that lua 5.1 is deprecated and won’t install)

2025-10-26: Unfortunately, homebrew no longer supports lua@5.1. So we can not install lua5.1 using homebrew. However, there are some other ways to install lua5.1, see the following posts:

Also in the repo of the lua package, the rockspec file needs to be the in the top level. For example, for this package https://github.com/leafo/magick, we can install it with lazy just like a normal plugin:

{
  "leafo/magick",
  build = 'rockspeck',
}

Lazy.nvim will automatically install and build it. The plugin will be installed under ~/.local/share/nvim/lazy-rocks, and lazy.nvim will also update the package.path, so that you can require/use the package.

For lua packages whose rockspec file are not in the top level, lazy.nvim seems can not correctly install them. For example, for this lua-toml package: https://github.com/jonstoler/lua-toml, lazy.nvim can not install it correctly: under ~/.local/share/nvim/lazy-rocks, the package does not exist, and lazy.nvim just treat it like a nvim plugin and put it under ~/.local/share/nvim/lazy/ instead, and the package.path is also not updated.

Using luarocks.nvim#

The second way is to use the plugin luarocks.nvim, and it works better.

Make sure to have all the requirements installed. Note that for luarocks.nvim, we do not need to install luarocks manually, the plugin will try to install/build luarocks automatically for you.

If you are using lazy.nvim as plugin manager, the plugin spec for luarocks.nvim looks like this:

  {
    "vhyrro/luarocks.nvim",
    priority = 1000, -- Very high priority is required, luarocks.nvim should run as the first plugin in your config.
    opts = {
      rocks = { "lua-toml" }, -- specifies a list of rocks to install
      -- luarocks_build_args = { "--with-lua=/my/path" }, -- extra options to pass to luarocks's configuration script
    },
  },

The LuaRocks packages are installed under the luarocks.nvim plugin directory:

~/.local/share/nvim/lazy/luarocks.nvim/.rocks

The package.path variable is also updated by luarocks.nvim. So after installing a package, you can simply use require() to import the package.