Learn to Code via Tutorials on Repl.it!

← Back to all posts
Notepad++ Python Script
gwhite5 (1)

To automate text editing tasks, I daily use Python scripts I've written for the Python Script plugin of the Notepad++ editor. I had nothing to do with the creation of the plugin, but here I'm providing information to help you in writing your own scripts.

Scintilla is an editor engine at the core of Notepad++. The Python Script plugin gives us access to the Scintilla API. There is no Linux version of Notepad++ but there is an editor in Linux based on Scintilla: Geany.

Python Script Plugin:

Python Script documentation:

Python Script forum:

Scintilla documentation:

In Notepad++ menu, “Settings / Shortcut Mapper / Scintilla commands” shows some key mappings of Scintilla commands.

To evaluate selected text as a Python expression, put it in the paste buffer, and display the result:

   OutputStr = str(eval(editor.getSelText()))
   notepad.messageBox(OutputStr, "EvalSelect", 0)

To add up all the numbers that can be parsed from selected text, put it in the paste buffer, and display the result:

   import re

   nums = re.findall("[-+]?\d+[\.]?\d*[eE]?[-+]?\d*", 
   output = 1
   for n in nums:
           x = int(n)
       except ValueError:
           x = float(n)
       output += x
   OutputStr = str(output)
   notepad.messageBox("Sum: "+OutputStr, "BlockMath", 0)