How can I create a Vim command and copy it’s results to clipboard?
I want to convert Markdown to HTML and copy the result to the clipboard. So far I got:
nmap md :%!/bin/markdown/Markdown.pl --html4tags
But this will substitute my opened file on Vim to the result of Markdown.
You didn’t say which system you’re using, but generally saving it in the
+register should work. You can call
system():The
system()function takes the second parameter (optional) as input to thecommand, and here I’m using a chain of other functions to retrieve the contents
of the current buffer. Not sure, but there should be a better way to do it (if
someone knows, please let me know).
Alternatively, you can pass
markdownyour file name as input directly:But keep in mind that you’ll need to write the file before calling this.
Two important notes: