You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: README.md
+25-11
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,7 @@ MultiReplace is a Notepad++ plugin that allows users to create, store, and manag
22
22
-[lvars](#lvarsfilepath)
23
23
-[lkp](#lkpkey-hpath-inner)
24
24
-[fmtN](#fmtnnum-maxdecimals-fixeddecimals)
25
+
-[Preloading Variables](#preloading-variables)
25
26
-[Operators](#operators)
26
27
-[If-Then Logic](#if-then-logic)
27
28
-[DEBUG option](#debug-option)
@@ -174,19 +175,13 @@ Initializes custom variables for use in various commands, extending beyond stand
174
175
175
176
Custom variables maintain their values throughout a single Replace-All or within a list of multiple Replace operations. Thus, they can transfer values from one list entry to subsequent ones. They reset at the start of each new document in **'Replace All in All Open Documents'**.
176
177
178
+
> **Tip**: To learn how to preload variables using an empty Find field before the main replacement process starts, see [Preloading Variables](#preloading-variables).
|`(\d+)`|`vars({COL2=0,COL4=0}); cond(LCNT==4, COL2+COL4);`<br>`if COL==2 then COL2=CAP1 end;`<br>`if COL==4 then COL4=CAP1 end;`|`1,20,text,2,0`<br>`2,30,text,3,0`<br>`3,40,text,4,0`|`1,20,text,2,22.0`<br>`2,30,text,3,33.0`<br>`3,40,text,4,44.0`| Yes | Yes | Tracks values from columns 2 and 4, sums them, and updates the result for the 4th match in the current line. |
180
183
|`\d{2}-[A-Z]{3}`|`vars({MATCH_PREV=''}); cond(LCNT==1,'Moved', MATCH_PREV); MATCH_PREV=MATCH;`|`12-POV,00-PLC`<br>`65-SUB,00-PLC`<br>`43-VOL,00-PLC`|`Moved,12-POV`<br>`Moved,65-SUB`<br>`Moved,43-VOL`| Yes | No | Uses `MATCH_PREV` to track the first match in the line and shift it to the 2nd (`LCNT`) match during replacements. |
181
184
182
-
An empty Find string (`*(empty)*`) can be used to set variables for the entire Find and Replace list without being tied to a specific Find action. This entry does **not** match any text but is executed once at the beginning of the **'Replace'** or **'Replace All'** process when **'Use List'** is enabled. It allows the Replace field to run initialization commands like `vars()` for the entire operation. This entry is always executed first, regardless of its position in the list.
|*(empty)*|`vars({ `<br>`VpersonName = FNAME:sub(1, (FNAME:find(" - ", 1, true) or 0) - 1),`<br>`Vdepartment = FNAME:sub((FNAME:find(" - ", 1, true) or #FNAME + 1) + 3, (FNAME:find(".", 1, true) or 0) - 1) })`| Extracts `VpersonName` and `Vdepartment` from the active document’s filename in the format `<Name> - <Department>.xml` using the `vars` action. Triggered only once at the start of the replace process when **Find** is empty. |
187
-
|`personname`|`set(VpersonName)`| Replaces `personname` with the content of the variable `VpersonName`, previously initialized by the `vars` action. |
188
-
|`department`|`set(Vdepartment)`| Replaces `department` with the content of the variable `Vdepartment`, previously initialized by the `vars` action. |
189
-
190
185
<br>
191
186
192
187
#### **lvars(filePath)**
@@ -198,10 +193,10 @@ The parameter **filePath** must specify a valid path to a file. Supported path f
198
193
- Forward Slashes: `"C:/path/to/file.vars"`
199
194
- Long Bracket String: `[[C:\path\to\file.vars]]`
200
195
201
-
**Example File:**
196
+
** File:**
202
197
```lua
203
198
-- Local variables remain private
204
-
localPATH=[[C:\Data\Projects\Example\]]
199
+
localPATH=[[C:\Data\Projects\\]]
205
200
206
201
-- Only the returned variables are accessible in Replace operations
207
202
return {
@@ -212,14 +207,15 @@ return {
212
207
}
213
208
```
214
209
210
+
> **Tip**: To learn how to preload variables using an empty Find field before the main replacement process starts, see [Preloading Variables](#preloading-variables).
|*(empty)*|`lvars([[C:\tmp\m\Vars.vars]])`| No | No | Loads variables such as `userName = "Alice"` and `threshold = 10` from `myVars.vars`. |
218
215
|`Hello`|`set(userName)`| No | No | Replaces `Hello` with the value of the variable `userName`, e.g., `"Alice"`. |
219
216
|`(\d+)`|`cond(threshold > 5, "Above", "Below")`| Yes | No | Replaces the match based on the condition evaluated using the variable `threshold`. |
220
217
221
218
**Key Points**
222
-
-**Initialization**: An empty Find string (*(empty)*) initializes variables globally at the start of the Replace or Replace All process when "Use List" is enabled. This initialization occurs only once, regardless of its position in the list.
223
219
-**Conditional Loading**: Variables can be loaded conditionally by placing lvars(filePath) alongside a specific Find pattern. In this case, the variables are only initialized when the pattern matches.
224
220
-**Local vs. Returned Variables**: Only variables explicitly included in the return table of the .vars file are available for use. Any local variables remain private to the file.
225
221
@@ -290,6 +286,24 @@ Formats numbers based on precision (maxDecimals) and whether the number of decim
290
286
291
287
<br>
292
288
289
+
### **Preloading Variables**
290
+
MultiReplace supports **predefining or loading variables** before any replacements occur. By separating initialization from the actual replacements, operations stay clean and maintainable.
291
+
292
+
#### 🔹 **How it works:**
293
+
-**Place `vars()` or `lvars()` next to an empty Find field.**
294
+
- This entry does **not** search for matches but runs before replacements begin.
295
+
- It ensures that **variables are loaded once**, regardless of their position in the list.
0 commit comments