This is how the code is copied to onenote with paste option : keep source formatting
If I select paste option : "keep text only", the indentations are preserved (and syntax highlighting is gone as expected)
If I copy the code to word with paste option : keep source formatting, it is copied perfectly preserving both indentation and syntax highlight.
Why is indentation lost in oneNote only?
Office version - 2013
VS code version - May 2017 (version 1.13)
OS - Windows 10 Pro
How do I fix indentation in Visual Studio? On Windows Shift + Alt + F. On Mac Shift + Option + F. On Ubuntu Ctrl + Shift + I.
Add Code Blocks in OneNote Let's say you want to store a code snippet in OneNote you might want to use later on. Click the NoteHighlight tab and select a language. In the pop-up window that appears, paste the code and click OK. Highlighted source code will show up on the page.
A simple fix is to try Ctrl + Shift + V after copying the code. It will paste all codes correctly with indentations in it.
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,
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  
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.
You can use Outlook email or Microsoft Word as a placeholder.
Steps:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With