11

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! (=

ELLIOTTCABLE
  • 2,708

3 Answers3

11

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()

matt0089
  • 103
  • 3
10

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.

Heptite
  • 20,411
6

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.