I realized that for a very basic lua debugging the most simple way is to write directly the code in the command line (no plugin, no DAP).

For example:

:lua print(vim.inspect(vim.api.nvim_list_wins()))

But debugging/tests would be much more convenient if I could have something like the command line in a dedicated window.

Is that possible?


3 Answers 3


The :%lua command executes all the lines of the buffer using the lua Neovim interpreter.

The :'<,'>lua command executes the selected line of the buffer using the lua Neovim interpreter.

For making tests:

  • I create an empty buffer (optionally I set its filetype to lua to get the lua colorization).
  • I type my commands
  • I select the ones that I would like to execute
  • I hit: :lua that execute :'<,'>lua and pass the lines to the Neovim interpreter.

e.g.: If you have a buffer with the following three lines:

n = 4
print("foo " .. tostring(n))

If you select the second and third line and hit :lua you'll get:

foo 4 
  • 2
    That's the basic debugging tool i wanted. Many thanks. Actually :'<,'>lua means "On this range of lines (that you selected in visual mode) execute lua". You can specify the lines manually also :3,6 lua Commented May 27 at 14:56
  • Thanks for the feedback! I'm glad you have solution to your problem :-) Commented May 27 at 14:57

This is not as sophisticated as using :[range]source/:[range]lua, but you can open a command-line window using q: (or :Ctrl+f).

Why is it less sophisticated? You can't enter multi-line commands (though | still works). Plus, the advantage of a dedicated buffer as in other answers is that you can write it out to a file somewhere and keep using it later.

  • Thank you for mentioning my answer before it was even written.
    – Friedrich
    Commented May 27 at 18:38
  • Thanks also. The conclusion of this question is "If you just want to debug your init.lua and to understand some plugins.....no need of a complex lua debugger: just use the neovim command line" Commented May 27 at 19:59

You can write Vimscript (including the :lua command) in any buffer. You can then either source the whole buffer with :source or prefix a range, e.g. :.source will work on the current line.

This way, you can develop your code and run it. When you're done you can write the buffer to a file.

See :help :source for reference.

  • Thanks for the :.lua, it completes my lua debugging skills. I never plan to do vimscript so for me i will forget source and just remember lua Commented May 27 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.