How to print a string with many lines and view it again with :messages?

When I use :lua print(vim.inspect(some_long_object)), it correctly displays the whole serialization of said object. However, when I use :messages to view the string again, I only see the bottom. The last 200 lines to be precise. According to :help :messages, the number of remembered messages is fixed at 200. But I didn’t use 200 messages, I created one big message with > 200 lines.

Is this a bug of neovim or am I missing something?

We usually use :echomsg to print messages displayed by :messages. But I’m not sure how to call it from Lua…

:echomsg doesn’t display new lines like print, but ^@ characters.

vim.pretty_print is a good shortcut, but has the same problem as print. I noticed vim.notify works, although plugins might monkeypatch it.

So, the best solution is to use:

:lua vim.api.nvim_echo({ { vim.inspect( some_long_object) } }, true, {})

it even allows me to pass the highlight group as the 2nd element of the first argument.

1 Like

you can use vim.notify(vim.inspect()) then you can use :message