8

So, if I get an error from a plugin, I'd like to be able to report that error on GitHub or similar.

Unfortunately, it's not mouse-selectable; and after appearing and asking me to hit RETURN, it seems gone forever.

  1. I've discovered that I can cause the errors to appear again using :messages or :3messages or similar; but they appear in the same fashion: un-selectable, useless.

  2. Another Stacker asked a similar question, which yielded the useful command :let @+=v:errmsg — but that only captures the very last line of the messages; many errors I see consist of multiple lines, all of which I'd like to select.

Please help me either A. turn a :messages window into a buffer, so I can use normal likewise-visual selection to copy what I want to report outside of Vim, or at least B. construct something I can throw into my .vimrc that will copy all of the lines of the most recent error onto my clipboard.

Thanks! (=

3 Answers 3

5

The answer by Heptite is a good way to do this using built-ins. If you're okay with using a plugin, my bufferize plugin automates the process a bit. Lets you just do:

:Bufferize messages

In order to get a preview buffer with the contents of that command's output.

As a side note, I'm surprised the :messages output is not selectable. I guess maybe you're using Vim with a GUI? With terminal Vim, you can select, and then middle-click-paste the content.

2
  • 1
    I'm not usually one for plugins over built-in features, but the built-in way in this case is so obtuse, and the plugin is so simple and ideal for exactly this situation. Have u an check, @Andrew! Great tool, I've been using it since this reply, and now it's a baked-in part of my Vim process. (= Apr 2, 2019 at 16:31
  • Thanks, always happy to hear someone likes a plugin of mine :). Apr 2, 2019 at 20:44
9

Try this:

:put = execute('messages')

Explanation:

  • :put {register} puts the contents of the register at the cursor location (like p in normal mode)
  • execute('messages') is a vimscript function that executes an Ex command, and captures it's output
  • ={vimscript expression} is the expression register, who's value is the result of the vimscript expression

So the above captures the output of the :messages command in the expression register, and puts the contents of the expression register at the cursor's location.

See :h quote=, :h :put, :h execute()

5
  • 1
    Code without any explanation is useless. Can you elaborate on this a little more?
    – Toto
    Sep 19, 2021 at 9:26
  • This is pretty straightforward. Open a new empty buffer and run the command -- it will paste the output of :messages command in to the current buffer. Feb 4, 2022 at 22:07
  • 1
    This approaches truncates messages. It does not work well if you have one long message across multiple screens
    – C.W.
    Jul 23, 2023 at 21:01
  • 1
    Thanks @NaotoTanaka, this was great! Much more convenient than :redir. I added a short explanation if that's good with you.
    – matt0089
    Mar 13 at 18:59
  • 1
    @matt0089 Thanks a great explanation! Mar 16 at 11:33
8

Try this:

:redir > messages.txt
:messages
:redir END
:e messages.txt

You can suppress output to the display while still capturing the messages output by changing :messages to :silent messages.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .