6

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,315
  • 3
  • 27
  • 41

3 Answers3

6

Try this:

:put = execute('messages')
NaotoTanaka
  • 61
  • 1
  • 1
  • 1
    Code without any explanation is useless. Can you elaborate on this a little more? – Toto Sep 19 '21 at 09: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. – Jongwook Choi Feb 04 '22 at 22:07
  • This approaches truncates messages. It does not work well if you have one long message across multiple screens – C.W. Jul 23 '23 at 21:01
5

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
  • 19,383
  • 5
  • 58
  • 71
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.

Andrew Radev
  • 406
  • 2
  • 6
  • 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. (= – ELLIOTTCABLE Apr 02 '19 at 16:31
  • Thanks, always happy to hear someone likes a plugin of mine :). – Andrew Radev Apr 02 '19 at 20:44