Reputation: 1479
In vim, how might a person paste styled text from the system clipboard rather than the plain-text?
For example, copying from a web browser and pasting in to a word processor typically results in styled text, including basic formatting (bold) and links, being pasted. How might a person copy from the browser in the same way but paste the original HTML representation of the text in to vim?
Upvotes: 6
Views: 1471
Reputation: 1
I don't know what the ZyX's answer was supposed to do in 2012. But in 2024 set clipboard^=html
throws an E474 error. Since this page appeared as the first google result when searching for "vim/neovim paste rich text clipboard" I'll leave my solution here.
I couldn't find any native Neovim functionality for this. So nothing has changed in this regard. But if you have wl-clipboard
(containing wl-copy
& wl-paste
) or x11's / xorg's analogs (like xclip
) installed you can bind this lua snippet as callback to <leader>ht
or <M-v>
for example:
local handle = io.popen("wl-paste -t text/html", "r")
# "*a" - Returns all the contents
local result = handle:read("*a")
handle:close()
if result then
vim.api.nvim_put({result}, "", true, true)
end
Upvotes: 0
Reputation: 53654
Temporary adding html
to clipboard
option should help:
set clipboard^=html
put +
set clipboard-=html
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. Only available with the |+multi_byte| feature.
Upvotes: 9
Reputation: 62568
Vim edits only plain text, more or less. In any case, what you're asking is not possible.
If you want you can look up source of the HTML page, and paste that in Vim, but that is still plain text (depends on the definition; I still view markup as plain text).
Upvotes: -2
Reputation: 196789
Vim doesn't support rich text: it's a text editor, not a word processor.
Upvotes: -2