Neovim for Beginners — Lua APIs

Learn the basics of Neovim Lua APIs.

5 min readAug 13, 2022


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.

Pretty Print

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.

  • vim.inspect (:h vim.inspect()) — Return a human-readable representation of the given object.
  • vim.print (: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

:lua print(vim.inspect(package.loaded))
:lua vim.print(package.loaded)
:lua =package.loaded
Neovim Pretty Print

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.

:enew|put=execute('lua =package.loaded')
Neovim Pretty Print to a Buffer

Alternatively, we can use the redir (:h redir) command.

:redir @a
:lua =package.loaded
:redir END

We redirect the command output to the register a. From the buffer, we can print out the register (“ap).

Neovim Redirect Command Output


vim.loop (: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.

Internally, vim.loop wraps the luv Lua bindings (:h luv-intro) for the LibUV library.

:lua =vim.loop




Software engineer, Data Science and ML practitioner.