Enzio
Enzio

Reputation: 889

Copying code from Visual Studio Code to OneNote loses tab indentations even though syntax highlighting is retained

This is how the code is copied to onenote with paste option : keep source formatting enter image description here

If I select paste option : "keep text only", the indentations are preserved (and syntax highlighting is gone as expected)

enter image description here

If I copy the code to word with paste option : keep source formatting, it is copied perfectly preserving both indentation and syntax highlight.enter image description here

Why is indentation lost in oneNote only?

Office version - 2013

VS code version - May 2017 (version 1.13)

OS - Windows 10 Pro

Upvotes: 5

Views: 2224

Answers (3)

FullStackCoder
FullStackCoder

Reputation: 530

You can use Outlook email or Microsoft Word as a placeholder.

Steps:

  1. Copy and paste from VS Code into Outlook email or Microsoft Word document.
  2. Copy and paste from Outlook email or Microsoft Word into OneNote.

Upvotes: 4

Voyager
Voyager

Reputation: 759

If you copy   fourspaces fourspaces from vscode to onenote

,onenote will show fourspaces fourspaces

The code   fourspaces fourspaces in vscode is stored at clipboard like this

<meta http-equiv="content-type" content="text/html; charset=utf-8"><div style="color: #bbbbbb;background-color: #282c34;font-family: Fira Code;font-weight: normal;font-size: 15px;line-height: 20px;white-space: pre;"><div><span style="color: #bbbbbb;">    fourspaces    fourspaces</span></div></div>

Onenote ignore spaces, but tab are formatted to &nbsp;&nbsp;&nbsp

One solution is convert all indentation to tabs in your file

Generally, you could add "editor.insertSpaces": false,in your user setting; VSCode - How do I set tab-space style?

Or there is a vscode plugin named S.T.O.N.E, you can use it.

Upvotes: 3

Ali80
Ali80

Reputation: 8676

As mentioned by @rambler OneNote ignores pasted spaces, the solution is converting all spaces to tabs in your document using:

ctrl+shift+p

then enter

convert indentation to tabs

now you can copy your code without problem,

if you want to make the tab indentation default you can change the setting by going to preferences and adding the following line:

"editor.insertSpaces": false,

Upvotes: 3

Related Questions