Open Notepad++, go to the Plugins drop-down menu. Open the Plugins Manager. Download PythonScript for Notepad++. You will be prompted to restart Notepad++. Do that.
When Notepad++ reopens, go to Plugins in the drop-down menu. Locate PythonScript. Click "new script". When prompted, save the script with a .py extension.
This is the code I used, which you may want to edit:
#*** IMPORTS ***
from Npp import *
#*** DEFINITIONS ***
initial_string="""
THIS IS A HUGE
STRING
WITH COMMENTS
AND FUNCTIONS
AND
NESTING varr
MISSPELLEDD WORDS
VARIABLES Varr
ALL KINDS OF CRAZY STUFF"""
#*** I am using a case-sensitive replacement; ***
#*** therefore, I use two replacement operations ***
#*** First replacement, lowercase ***
print initial_string
user_replacement_string=notepad.prompt(notepad, 'Replace', "")
#*** Second replacement, uppercase ***
editor.replace("varr", user_replacement_string)
user_replacement_string=notepad.prompt(notepad, 'Replace', "")
editor.replace("Varr", user_replacement_string)
Save.
Now, create a new file ctrl-n and test the script. Go to Plugins->PythonScript->Run Last Script. If it works, you can put it to action in the file you're working on.
For convenience, I made ctrl-shift-e a shortcut key for the Run Previous Script (#yourscriptname.py) command. In your drop-down menu, go to Settings->Shortcut Mapper. Click the Plugin commands tab. Near the end, Run Previous Script. Very handy.
Interestingly, you can use this script to duplicate itself for different patterns. I would really like to know how to make that possible. Please see the edit on my question.
IMPORTANT EDIT
The below code will make it so that your Notepad++ will create its own scripts. Run this script, and save the file in your c:/program files/Notepad++/plugins/config/PythonScript/scripts directory {Windows default}:
#imports
from Npp import *
#variables
pattern_string=notepad.prompt(notepad, 'Pattern String')
number_of_replacements=int(notepad.prompt(notepad, 'Number of Replacements'))
variable_to_replace = []
replacement_title = []
the_header = """#imports
from Npp import *
#definitions
"""
a = "pattern_string = """ + '"' + '""' + pattern_string + '""' + '"'
b = """
print pattern_string
user_replacement_string"""
c = """=notepad.prompt(notepad, 'Replace', "Replaces: """
d = '"' + """)
editor.replace(""" + '"'
e = """", user_replacement_string"""
f = ")"
#function
for i in range (0, number_of_replacements):
replacement_title.append(str("Replacement Item ") + str(i+1))
variable_to_replace.append(notepad.prompt(notepad, replacement_title))
print the_header + a
print b + str(i) + c + variable_to_replace[i] + d + variable_to_replace[i] + e + str(i) + f
#thanks Wolfpack08.
It will make it so that you can import strings that you often paste into your file, along with variables that you often have to replace. Write your input pattern with variables (i.e.,
This is my stupid input pattern foo and I use the common variable bar.
When you run the script, you specify that input pattern in the first pop-up. You then specify the number of variables in the input pattern: foo and bar (e.g., "2" variables). In the resulting pop-up input boxes, you specify the variables in the order you would like to replace them in: ("foo", "bar").
I didn't put a 'default value' function in because I thought it would be annoying. I think it would be very useful to have default values for people who do a lot of data entry and need this kind of macro, though. If anyone makes a request for one, I will add it.