Project Find and Replace to exclude or include dialogue

I just love the project find and replace functionality. I used it recently when I wanted to change from 1st person to 3rd person. But replacing all the “I”'s with “Character Name” would cause any “I” within the dialogue to change also - which wouldn’t be right. I can also see situations where I’d want to only change something within the dialogue throughout the project. Thus having an option to include or exclude dialogue when using the project find/replace would be very helpful.

This would probably take quite a lot of work to pull off well, especially at the kind of level I think you’re referring to, within the Project Replace tool. The main issue is that Scrivener’s scriptwriting support is built on top of something that has no idea what any of this is. We basically have to look at the line your cursor is on, and if it matches a bunch of precise formatting details (like this much margin, that much indent, and this much post-line spacing) that match a definition held elsewhere, then we know that’s a Dialogue line, or Action.

Going through line by line and figuring that all out is a slower process. It’s something we do have code for, after all that is what the compiler does when it turns these detected formatting rules into FDX elements or whatever, but it’s not optimised for a scenario where one would want to pull out only Character element lines, say, and change just those.

It’s not a bad idea, and I think it’s worth putting on a list, but I wouldn’t expect it any time soon, is what I’m getting at, since it would require a lot of rewiring in my estimation. Bear in mind the current engine may work on a totally different premise, where the whole section is replaced as a single entity rather than line by line. Such changes can make a global replace function go from taking 8 seconds to 187 seconds, if you get what I mean.

I don’t think the OP is talking about a script, though. (If they were, there wouldn’t be any occurrences of ‘I’ outside dialog to replace!)

And if we are talking ordinary text (not script-formatted) and where dialog is marked off with double-quote marks, an algorithm that exempts from replacement what is in quotes (or vice versa) would be much more doable.

1 Like

Yes, that’s what I was referring to, a script. A script in Scrivener is a rigid set of formatting commands (kind of like styles), with a recognition system on top that detects what scripting element the cursor is in, based on the shape of the paragraph. That’s the part that might get computationally expensive when you’re replacing text across a thousand lines, and there is no framework for doing such at the moment (outside of compiling).

Prose dialogue might be doable, as we do have code for that with the Direct Speech filter that can highlight such. That can even detect less common formats, such as — This is dialogue.

Edit: Oh wait, I read you wrong as well. :slight_smile: Well, either way, it would take some rewiring. Like I said, one for the list either way.

Even if it were doable, limited to speech formatted with double quotes, there would always be the risk of a typo here or there that added a space or removed one adjacent to a quote mark and threw the whole thing off. This happens even now with the Direct Speech option in Linguistic Focus—sections that were intended to be direct speech are not highlighted as such because the quote marks don’t match as expected. Of course, seeing that can be a valuable editing tool, too! :slight_smile: But in a project-wide replace you can’t see what’s about to be changed. So that’s something else to think about in how this might work. (Granted, you’re always running a project replace at your own risk…!)

That said, the Edit ▸ Writing Tools ▸ Linguistic Focus... on Mac or Edit ▸ Writing Tools ▸ Dialogue Focus... on Windows may still be a current helpful tool. It wouldn’t limit the replacements, but it would allow you to see clearly whether certain text was direct speech when using the document Find and Replace. So jumping through with Find and Replace & Find would be faster.

1 Like

Is that really what you did? A one-shot Replace of all the I’s to Character Name?

I would think a significant percentage of the I’s would become pronouns, or that some other tweak would be necessary to the containing sentence. This would require you to step through them all, so you could decide how to handle each one.

But perhaps I’m overthinking it.


The job would likewise require judicious review of non-dialogic instances of ‘we’, ‘us’, ‘our’. As well as straight-out replacement of non-dialogic ‘me’, ‘my’ and ‘mine’.

1 Like

Correct - I was not talking about a script. Thanks for clarifying.

Yes, that is what I did. I was switching from first to third person POV. I evaluated other ways but this seemed the least costly. But yes, it did create a mess in the dialogue where another person said, “I did this…” and it changed that to my main character’s name. All in all it worked with a lot of editing but less than I would have done with other options.

1 Like