Quantcast
Channel: How to send rich text to the clipboard from command line? - Super User
Viewing all articles
Browse latest Browse all 4

Answer by Ricardo Kullock for How to send rich text to the clipboard from command line?

$
0
0

Also a Pandoc Solution

Developing on the answers here

Alternative 1

  • Use :TOhtml, this will give you a new buffer with the converted html. Next, use :w ! xclip -t text/html -selection clipboard

  • When I pasted this in libreoffice, it had the line numbers. I tried disabling them, and repeating. This worked nicely.

Solution using Pandoc:

  • I prefer this, has a better formatting, and it is a one-liner

    :w ! pandoc -s -t html | xclip -t text/html -selection clipboard

Some explaining:

  • :w ! {cmd} will pipe the buffer to {cmd} in the shell command
  • pandoc -s -t html will take the input and convert to html. I think you can omit the "-t html"
  • "|" works as a pipe, since it's being interpreted as a shell command
  • xclip -t text/html -selection clipboard is the answer given in the link linux answer

EDIT:Trying to assign the command to a keybinding didn't work. It seems like the pipe is being used in the usual vim sense.

My workaround was to define a function:

function Html()    let mytext = execute('w ! pandoc -s -t html | xclip -t text/html -selection clipboard')    return mytextendfunction

And then assigning a keybind to call this function:

nnoremap <leader>h :call Html()<cr>

Hope this helps. If anyone has a simpler solution, please comment!


Viewing all articles
Browse latest Browse all 4

Trending Articles