Skip to content

Instantly share code, notes, and snippets.

@jpvanoosten
Created May 31, 2021 21:05
Show Gist options
  • Save jpvanoosten/5b247b127256657a47d38fc4a62ede21 to your computer and use it in GitHub Desktop.
Save jpvanoosten/5b247b127256657a47d38fc4a62ede21 to your computer and use it in GitHub Desktop.
Using the Notepad++ Python Script plugin, you can use Python to perform complex editor operations with a single button. This script replaces the '<' and '>' characters with the HTML equivalents to enable copy-pasting source code into HTML.
# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
editor.beginUndoAction()
selectionLength = editor.getSelectionEnd() - editor.getSelectionStart()
start = editor.getSelectionStart() if selectionLength > 0 else 0
end = editor.getSelectionEnd() if selectionLength > 0 else editor.getLength()
# editor.replace("&", "&amp;", 0, start, end)
editor.replace("<", "&lt;", 0, start, end)
editor.replace(">", "&gt;", 0, start, end)
# End the undo action, so Ctrl-Z will undo the above actions
editor.endUndoAction()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment