FG
💻 Software

Reverse line order in Notepad++

Fresh3 days ago
Mar 15, 20264921 views
Confidence Score0%
0%

Problem

Is there a way to reverse the line order (considering line break) of a file using Notepad++? Input: Line 1 Line 2 Line 3 Required Output: Line 3 Line 2 Line 1 Any plugin/macro is OK

Error Output

\r\n

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Unverified Fix
New Fix – Awaiting Verification

Reverse Line Order in Notepad++ Using Python Script

Low Risk

Notepad++ does not have a built-in feature to reverse the order of lines in a document. However, it allows the use of Python scripts through the PythonScript plugin, which can manipulate text within the editor.

Awaiting Verification

Be the first to verify this fix

  1. 1

    Install PythonScript Plugin

    Open Notepad++, go to 'Plugins' > 'Plugins Admin', find 'PythonScript' in the list, check it, and click 'Install'. This will enable scripting capabilities in Notepad++.

  2. 2

    Create a New Python Script

    After installing the plugin, go to 'Plugins' > 'PythonScript' > 'New Script'. Name the script 'ReverseLines.py'. This will open a new editor window for your script.

  3. 3

    Add Code to Reverse Lines

    In the script editor, paste the following code to reverse the lines of the current document: ```python editor.beginUndoAction() text = editor.getText() lines = text.splitlines() lines.reverse() editor.setText('\n'.join(lines)) editor.endUndoAction() ```

    python
    editor.beginUndoAction()
    text = editor.getText()
    lines = text.splitlines()
    lines.reverse()
    editor.setText('\n'.join(lines))
    editor.endUndoAction()
  4. 4

    Run the Script

    Go to 'Plugins' > 'PythonScript' > 'Scripts', and select 'ReverseLines.py' to execute the script. This will reverse the order of lines in the active document.

  5. 5

    Save Your Changes

    After running the script, review the output in the editor. If the lines are reversed as expected, save the document to keep the changes.

Validation

To confirm the fix worked, check that the lines in the document are now in reverse order compared to the original. The last line should now be at the top and the first line at the bottom.

Sign in to verify this fix

Environment