Neovim for Beginners — Lua APIs

Learn the basics of Neovim Lua APIs.

alpha2phi
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')

--

--

alpha2phi

Software engineer, Data Science and ML practitioner.