Neovim for Beginners — Lua APIs
In this article, let’s learn a few tricks using the Neovim Lua APIs.
This article is part of the Neovim for Beginners series.
The Neovim configuration files are available in this repository.
As we learn to configure Neovim, we may need to inspect the content of a Lua variable or object. Neovim provides these 2 APIs to help.
:h vim.inspect()) — Return a human-readable representation of the given object.
:h vim.print()) — Print the given arguments in a human-readable format.
E.g., if we want to display the loaded packages (
:h package.loaded), we can use either
The output is in the command buffer which makes it difficult to read. We can use the
execute command (
:h execute) to display the output in a new buffer.
Alternatively, we can use the
:h redir) command.
We redirect the command output to the register
a. From the buffer, we can print out the register (
:h vim.loop) exposes all features of the Neovim event-loop. It is a low-level API that provides networking, filesystem, and process management functionality.
vim.loop wraps the
luv Lua bindings (
:h luv-intro) for the LibUV library.