I'm using TSServer with LSPConfig to provide in-line typechecking with Neovim.

Is there a way for me to grab the value of a given type error message?

Especially to my system clipboard?

  • Welcome to Vi and Vim! If the text is an "overlay" (or ghost text, or virtual text), I'm not sure it's easily copyable. But you can often run the linter/compiler/other program that produced the message directly. (FWIW: this is why I prefer popups to virtual text: the text is selectable.) One exception: you might be able to copy virtual text if it appears in a Vim inside tmux (using tmux's copy/paste features).
    – D. Ben Knoble
    Mar 27, 2023 at 15:32
  • 1
    Similar question asked here and here. Jan 18 at 10:50

2 Answers 2


To open it as a floating window, do :lua vim.diagnostic.open_float(). If you do that again, you will move into the window. Then you can copy the line you need to the system clipboard with "+yy.

I have bound the above function to <leader>e as follows, so I would then do <leader>e twice to jump inside the buffer, and then copy as above:

local on_attach = function(_, bufnr)
    local opts = {noremap = true, silent = true}
    vim.api.nvim_buf_set_keymap(bufnr, 'n', '<leader>e',
                                '<cmd>lua vim.diagnostic.open_float()<CR>', opts)

And then pass that to lsp.clangd.setup { on_attach = on_attach }. You should have your own vimrc/lua/custom_lspconfig.lua, where you add such LSP-bindings, so that they are only bound for the local buffer when an LSP is attached. Mine is here, if you want more context.


See this reply

That message should be in either v:statusmsg or v:errmsg,. You can put those values into the system clipboard via:

:let @+ = v:statusmsg
  • 1
    Thank you for writing an answer. The bulk of it is a quotation from the answer you refer to. I think your answer could be improved if you just wrote down your own observations (you did test this works?) and rephrased (e.g. "is" instead of "should")
    – Friedrich
    Aug 25, 2023 at 11:27
  • you have misunderstood the question. This is not a duplicate of the other question you linked to. We need the message given by the LSP server, which is shown in floating red text, for example "header <iostream> not found in system paths" ... it is not a vimscript / lua error at all, it's just the floating text given by the linter or language server. Jan 18 at 9:29

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.