Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

libreoffice-paste-from-vscode

EN | RU

1. Description

This is the macros for LibreOffice to paste copied code from VS Code with preserve syntax highlighting and indents.

2. The problem

VS Code implemented very useful feature - preserve code formatting when copying text. When pasting into Microsoft Word - it will keep the colors and indents of the code:

VS Code

Microsoft Word

But when pasting into LibreOffice Writer, the situation is different - we have two choices:

LibreOffice - Paste Special

  • HyperText Markup Language (HTML): This option will preserve colors, but not the indents:

    LibreOffice - Paste HTML

  • Unformatted text: This option will preserve indents, but not the colors:

    LibreOffice - Paste Unformatted

(On the LibreOffice screenshots above, background color Dark Grey 4 was added to the paragraphs with code)

So why this is happening and how to make pasting work properly in LibreOffice too?

3. The solution

At first I thought it was some LibreOffice setting. But found nothing except maybe autocorrect (Tools - AutoCorrect - AutoCorrect Options...):

LibreOffice - Disabling delete spaces

But disabling settings about spaces did not change anything.

Next I found unanswered question here and then here. On the second post the pawel229 user posted his solution, which became the base of my.

The solution is simple - because we have both styling and indents info in clipboard, we simply need to paste our code with style, and then insert indents for each line. The source code for the macros to do that is in file indentation_macro_code.vb.

4. Installation and usage

You need:

  1. Copy contents of the file indentation_macro_code.vb;

  2. Open LibreOffice Writer;

  3. Select Tools - Macros - Edit Macros...;

  4. Open My Macros & Dialog - Standard - Module1 and paste code from indentation_macro_code.vb. Result should look like this:

    LibreOffice - Macros created

  5. Now open Tools - Customize... - Keyboard. Select Keyboard tab. Choose LibreOffice radio-button in the right-top corner. Now in Category choose Application Macros - My Macros - Standard - Module1. Select CopyIndentation in Function. Now in the Shortcut Keys select, for example, Alt+V and press Assign:

    LibreOffice - Macros hotkey

  6. Press OK;

  7. Now you can copy some code from VS Code and paste in using Alt + V hotkey. Result:

    LibreOffice - Pasted via macros

    (I had to insert 2 spaces in the first line and apply Dark Grey 4 color to the background of the paragraphs)

5. Contribution

Feel free to contribute via pull requests or issues!

About

Macros for LibreOffice to paste copied code from VS Code with preserve syntax highlighting and indents

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages