Reputation: 93
If I press any key, the message will disappear.
I already know use : message
to show the error message but I can't copy it to my register or print it to the .txt file.
I have read the help message, googled the question.
Upvotes: 5
Views: 1417
Reputation: 140
To copy the error msg I found this useful:
let @* = execute('messages')
That will copy to the clipboard.
Another option is to write it on the buffer:
:put =execute('messages')
From this post: https://vi.stackexchange.com/questions/31067/copy-vim-messages-into-clipboard
Upvotes: 1
Reputation: 31
it's easier to resolve by starting vim with --log
option to logging to file
vim --log /tmp/vim.log
Upvotes: 1
Reputation: 15081
The last error message should be available in a builtin variable named v:errmsg
and the last status message is in v:statusmsg
.
There's also :h execute()
function which runs any VimScript command and returns its output.
Here's a generic mapping with redirection to the current buffer:
nnoremap <silent><leader>x :put =trim(execute(input(':', '', 'command')))<CR>
Press <leader>x
, then enter your command, such as 5mess
and press <Enter>
. The last five message lines will be added to the current buffer.
Upvotes: 4