1

If I copy a selection from a webpage in Firefox or Chrome, I can paste into eg Thunderbird and retain formatting, links etc.

Is it possible to copy a selection of text with links etc in browser and paste into vim and retain the formatting/links etc?

I believe Notepad++ can do this.

2 Answers 2

3

The simple answer is no, it's not possible.

Vim is a text editor which handles text files:

  • It can't decide how to keep the formatting of e.g links: Is it supposed to past them as markdown [link](destination) as html <a> elements, etc...
  • It can't keep the font size when you can only have one font size in a buffer
  • It can't keep the colors and the font family when it must respect your colorscheme
  • and so on

So maybe if you have a precise idea of how you want to transform the text you paste to look the way you want in Vim you could use an autocommand to be executed each time something is put in the buffer from the external register and process the text with vimscript but that will be not trivial to do.

2
  • 2
    This is actually one of the things I use Vim for. I paste and then copy text to strip all formatting.
    – Davo
    Apr 22, 2021 at 16:24
  • I'm surprised that there's not some way to grab and process the additional information that's included when I copy text from a webpage or email client. I must admit, my only real interest is grabbing the URL behind textual links, and perhaps information regarding formatting.
    – Tom
    Apr 27, 2021 at 2:28
2

Copying ZyX's answer from SO.

Temporary adding html to clipboard option should help:

set clipboard^=html
put +
set clipboard-=html

:help clipboard-html:

When the clipboard contains HTML, use this when pasting. When putting text on the clipboard, mark it as HTML. This works to copy rendered HTML from Firefox, paste it as raw HTML in Vim, select the HTML in Vim and paste it in a rich edit box in Firefox. You probably want to add this only temporarily, possibly use BufEnter autocommands. Only supported for GTK version 2 and later.

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.