How to copy code from Visual Studio Code to OneNote with indentation

microsoft-onenotevisual-studio-code

When I copy code form VS Code to OneNote, indentation is lost.

Example:
This is how code on VS Code looks like:
enter image description here

When it's pasted to OneNote, it looks like this (indentation is lost):
enter image description here

I wonder is there any way to copy code to OneNote without losing indentation.


Tried actions that didn't solve the problem:

  • Converting indentation to tabs or spaces on VS Code doesn't work.

    • if you use "spaces" for your indentation then change that to
      "tabs"using the below steps and then copy the code to oneNote.

      Steps:

      • 'ctrl + shift + p'
      • find command "convert indentation to tabs"
      • copy the code and paste it in oneNote

        quote from Dark Light's answer


Side observations:

  • It works perfectly when pasting code to Word. It looks like this when pasted to Word:
    • enter image description here

Best Answer

if you use "spaces" for your indentation then change that to "tabs"using the below steps and then copy the code to oneNote.

Steps:

  • 'ctrl + shift + p'
  • find command "convert indentation to tabs"
  • copy the code and paste it in oneNote

This works for me.

Related Question