The least you need to know:
- files are processed sequentially
- FIND once and operate many
- work sequentially from before to after
Just to be clear on this, whenever you use OPEN it is intended that a files are processed sequentially. You should never FIND something that is towards the bottom of the file followed by FINDing something that is before it. For example if you FIND something on line 100, you are going to fail if you try FINDing something on line 99. Also it assumed that you will only OPEN a files once.
FINDing and IN-LINE FINDing
For both FIND and IN-LINE, you must only attempt to FIND a block or fragment once. Once it is found you may perform as many relevant actions on it that you can. Therefore FIND -> BEFORE, ADD -> IN-LINE FIND -> IN-LINE BEFORE, ADD is valid. Unfortunately a previously acceptable method of keeping each command contained within its own block can no longer be allowed. For example the following is now unacceptable: FIND -> BEFORE, ADD -> FIND (the same line) -> IN-LINE FIND -> IN-LINE BEFORE A full explanation for this is here.
A rule of thumb when manipulating code around a FIND block is to work sequentially from before to after. The only real reason for this is because a FIND block is committed to the file after performing an AFTER, ADD and no other commands can occur on that FIND block.
So if you had several commands to do after the FIND, the best sequence would be BEFORE, ADD -> IN-LINE commands *or* REPLACE -> AFTER, ADD. The same applies for IN-LINE FIND. The commands are best ordered as IN-LINE BEFORE, ADD -> IN-LINE REPLACE -> IN-LINE AFTER, ADD.
Lastly, remember that IN-LINE commands go with IN-LINE FIND and the other commands (like AFTER, ADD) go with FIND. You cannot mix and match the commands. For example, and AFTER, ADD command will not add text after an IN-LINE FIND fragement, it can only add completely new lines after a FIND block.