7

When I'm confronting a bug of a plugin and an error message pops up like this one:

E5018: Error executing lua ...

and if I want to report this bug, I always have to type this error message manually. How can I copy the error message into my clipboard in order to paste it on github?

2 Answers 2

7

You can typically see the error messages produced by plug-ins using the :messages command.

If you'd like to put those messages into a Vim buffer, so that you can copy them to the clipboard from there, you can use the following command:

:put =execute('messages')

This uses the execute() function to capture output of an Ex command, then the expression register "= to use that in a register context and finally the :put command to append the contents of that register to the current buffer.

See :help :messages, :help execute(), :help "= and :help :put for more details.

1
  • 4
    Or let @* = execute('messages'); very clever idea
    – D. Ben Knoble
    Commented Apr 24, 2021 at 19:59
4

I combined @filbranden's answer with the answer to https://stackoverflow.com/questions/59474914/how-to-copy-the-error-message-when-vim-start

and came up with this leader shortcut that copies the last message displayed by Vim to the clipboard - uses @D.BenKnoble's suggestion from the comments:

nnoremap <leader>m :let @*=trim(execute('1messages')) \| echo 'copied' <cr>
4
  • How about nnoremap <leader>m :let @* = trim(execute('1messages')) <bar> echo 'copied'<cr> (the main difference is the <bar>)?
    – D. Ben Knoble
    Commented Oct 7, 2021 at 23:59
  • @D.BenKnoble I like your version better but for some reason I can't get it to work. When I try to save my my .vimrc I get E121: Undefined variable: cr - I can't figure out why <cr> is accepted in my version but not yours. btw I'm using MacVim, maybe it's a subtle difference
    – subelsky
    Commented Oct 9, 2021 at 15:08
  • You could try with caps <CR>, but I also forgot I had to escape the |
    – D. Ben Knoble
    Commented Oct 9, 2021 at 15:29
  • 1
    ahh, escaping | is what made it work - didn't matter whether <CR> was capitalized. will update the answer
    – subelsky
    Commented Oct 10, 2021 at 18:04

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.