vimtricks.wiki Concise Vim tricks, one at a time.

How do I evaluate and pretty-print a Lua expression from the Neovim command line without writing print(vim.inspect(...))?

Answer

:lua = {expression}

Explanation

In Neovim, :lua = expr is a shorthand that evaluates a Lua expression and pretty-prints the result using vim.inspect(). This is equivalent to :lua print(vim.inspect(expr)) but far faster to type, making it an invaluable tool for debugging configuration, inspecting API return values, and exploring Neovim's Lua environment interactively.

How it works

  • :lua = expr evaluates expr and calls print(vim.inspect(result)) on it
  • Works with any Lua expression: tables, strings, functions, API calls
  • Modeled after Lua's interactive mode where = expr prints the value

Example

Inspect the currently attached LSP clients:

:lua = vim.lsp.get_clients()

Check a specific option value:

:lua = vim.opt.foldexpr:get()

Inspect a table:

:lua = { a = 1, b = { nested = true } }

All three commands print a formatted, readable representation — no extra typing required.

Tips

  • Combine with vim.fn.* calls to inspect Vimscript function results: :lua = vim.fn.expand('%:p')
  • Use :lua = (no expression) to get an error — it expects a value, not a statement
  • For statements (no return value), use plain :lua without =: :lua vim.opt.number = true
  • Available since Neovim 0.7

Next

What is the difference between the inner word (iw) and inner WORD (iW) text objects in Vim?