Date: prev next · Thread: first prev next last
2025 Archives by date, by thread · List index


I hit the classic Writer issue: want to turn hard paragraph breaks (Enter/¶) into soft line breaks (Shift+Enter/↵). Ctrl+H/regex looks like it should work, but in practice it is inconsistent, and a global replace can also mess with headers/footers.

If you prefer a transparent solution over an extension, here is a small LibreOffice Basic macro that works on the current selection only, and walks backwards so it does not skip paragraphs:

+++ CODE
Sub ParagraphsToLineBreaks
    Dim oDoc As Object, oSel As Object, oRng As Object
    Dim oText As Object, oEnum As Object
    Dim aEnds() As Object
    Dim n As Long, i As Long
    Dim oPara As Object, c As Object

    oDoc = ThisComponent
    oSel = oDoc.getCurrentController().getSelection()

    If oSel.getCount() = 0 Then Exit Sub
    oRng = oSel.getByIndex(0)

    oText = oRng.getText()
    oEnum = oRng.createEnumeration()

    n = 0
    While oEnum.hasMoreElements()
        oPara = oEnum.nextElement()
        ReDim Preserve aEnds(n)
        aEnds(n) = oPara.End
        n = n + 1
    Wend

    For i = n - 2 To 0 Step -1
        c = oText.createTextCursorByRange(aEnds(i))
        On Error Resume Next
        c.goRight(1, True)     ' select ¶
        If Err = 0 Then
            c.String = Chr(10) ' replace with ↵
        End If
        Err = 0
        On Error GoTo 0
    Next i
End Sub
+++ END OF CODE

Usage: select only the body text you want to convert (or copy selection into a new doc first), then run the macro. Non-printing chars: Ctrl+F10 (¶ vs ↵).

Full note/explanation: https://lab.vanderworp.org/notes/writer-replace-paragraph-with-line-break/

--
To unsubscribe e-mail to: users+unsubscribe@global.libreoffice.org
Problems? https://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/
Posting guidelines + more: https://wiki.documentfoundation.org/Netiquette
List archive: https://listarchives.libreoffice.org/global/users/
Privacy Policy: https://www.documentfoundation.org/privacy

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.