Pasting from Sublime Text without default formatting

Hi. I have a bunch of code that i would like to paste in a writer document and i want to paste it with the format of Sublime Text, copying directly from the editor, but every time i paste it applies the ‘default paragraph style’ and if i ‘paste special’ → ‘unformated text’ it does the same.
Any idea?
Picture of the format desired:

Thank you for your help!

From what I see on Wikipedia, Sublime Text is a text editor, meaning it handles plain text files without formatting instructions (fortunately for the compilers).

What you see in the editor screen is some courtesy decoration to help you write your code. This decoration is not intended to be exported. When you copy something, the editor puts only text into the clipboard. This means LO Writer will have only unformatted text.

You can decorate the code in Writer the same as in Sublime Text. But this will cost you a few character styles.

Globally, the code will be assigned built-in paragraph style Preformatted Text which will likely need to be customised for your preferred font, size, indents, … You create a few character styles like Keyword (for let, function, …), String, Variable, Function, … You give these character styles the same colour as Sublime Text. Double-click on a word and assign the character style.

1 Like

Thank you so much. I thought i could just paste it with the original format, it works for Visual Studio Code but not with Sublime Text.

This is how I handle it in one of my technical documents. Everything is formatted with ad hoc paragraph and character styles, no direct formatting. Thus, I can dramatically change the look of the final document only tweaking the styles, absolutely no manual editing in text.


1 Like

It has no means to export? Maybe it includes a format that convey the color formatting.

1 Like

For anyone interested i discovered a package for Sublime which is called ‘Highlight’ which lets you copy the code as RTF. Then you go to LibreOffice and paste special as RTF.
Only problem, i am not using a theme, it’s a color scheme which is not the original so doesn’t let me copy exactly as it looks and doesn’t let me configure highlight to that color scheme (as it is not a theme). I will keep investigating.

Did you see this LibreOffice extension, Code Highlighter 2 » Extensions ?

1 Like

Interesting! thanks a lot