Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy formatted code to clipboard in VS Code

In Visual Studio Code, is it possible to copy selected code to the clipboard with the syntax highlighting? I want to be able to paste into a Word doc or e-mail.

Regular Visual Studio does this by default (it puts both text and RTF formats on the clipboard).

I see that I can "Toggle Developer Tools" and locate the div (with class="view-lines") that has the code, so maybe there is a way to use that chunk of html, but I don't see an easy way to just copy the formatted code and paste into Word or an e-mail.

like image 499
Thomas Avatar asked Feb 26 '16 20:02

Thomas


People also ask

How do I copy formatting code in Visual Studio?

Go to Tools -> Options. type copy in the search box. Under Text Editor -> Advanced ... Check Copy rich text on copy/cut.

How do I copy and paste code from VS Code?

“copy paste above line in vs code” Code AnswerOn Windows: Shift + Alt + Up/Down. On Mac: Shift + Option + Up/Down. On Ubuntu: Ctrl + Shift + Alt + Up/Down.

How do you copy a style code?

Select the portion of code you'd like to copy, then go the Edit menu and select Copy Special -> Copy as RTF. Your code, complete with syntax highlighting colors, is now stored on the clipboard. Simply press Ctrl + V in your other application to paste the code with syntax highlighting. It's that simple!

How do I copy code snippets in VS Code?

Open code file or select code snippet in Text Editor, then press F1 and then select/type Copy Syntax , or right click the Text Editor and then click Copy Syntax in context menu, the code with syntax highlight will copy to clipboard.


2 Answers

According to the 1.10 changelog : https://code.visualstudio.com/updates/v1_10#_copy-with-syntax-highlighting

It is now possible with that command : editor.action.clipboardCopyWithSyntaxHighlightingAction

Type/paste it in command box (ctrl+shift+p or F1)

like image 117
Mistermatt Avatar answered Oct 17 '22 22:10

Mistermatt


Use the command "Copy With Syntax Highlighting".

  1. Highlight the code
  2. Ctrl + Shift + p to open the Command Palette
  3. Type / Select Copy With Syntax Highlighting

It is available since VS Code v1.43 (Feb 2020), as @robert4 mentioned in comment.

like image 41
yhd.leung Avatar answered Oct 17 '22 23:10

yhd.leung