How do I quickly evaluate and print a Lua expression in Neovim without calling print()?
Answer
:lua =expr
Explanation
In Neovim, prefixing a Lua expression with = on the :lua command line evaluates it and pretty-prints the result using vim.inspect. This is the fastest way to explore the Neovim API, inspect configuration values, or debug Lua code without writing a dedicated print statement.
How it works
:lua— execute Lua code in Neovim's embedded Lua runtime=expr— the=prefix is syntactic sugar forprint(vim.inspect(expr))
Without =, you would need:
:lua print(vim.inspect(vim.api.nvim_list_bufs()))
With =, this becomes:
:lua =vim.api.nvim_list_bufs()
Example
Inspect which buffers are open:
:lua =vim.api.nvim_list_bufs()
Output: { 1, 2, 5 }
Check the value of an option:
:lua =vim.o.tabstop
Output: 4
Inspect a complex object:
:lua =vim.lsp.get_clients()[1]
Output: a fully formatted table with all client fields.
Tips
- This only works in Neovim; standard Vim does not have
:lua - The
=prefix usesvim.inspectinternally, so nested tables and non-printable types are shown clearly - Combine with
vim.fnto call Vimscript functions::lua =vim.fn.expand('%:p') - Works interactively in the command line window (
q:) too, making it ideal for exploratory sessions