Remove Empty Lines at the End of a Text Document (Scene) in Scrivener

I have a project with folders as chapter titles and text documents as scenes. I’ve noticed that sometimes I accidentally leave a “return” (an empty line) at the end of a scene (text document). Since these aren’t between paragraphs, the “Text Tidying - Remove Empty Lines” feature doesn’t work in this case. Does anyone know of a way to remove these “pilcrows” (¶) or empty lines?

Thanks in advance!

PS: I was not referring to the compile function. With RegEx \n\n$ could manage to find the trailing spaces, unfortunately I cannot replace them with an empty field.

:slight_smile:
Mark

4 Likes

Thank you, this might come in handy! But here I was referring to scrivenings or editng mode, not to the compile adventure.

You can use the Find/Replace mechanism to replace double pilchrows with single ones.

To search for whitespace characters, copy and paste from the text.

1 Like

Using RegEx, you’d simply replace \n\n with \n. There has to be an “end of paragraph” for the last paragraph with text in the document, which is why you can’t replace \n\n with nothing.

:slight_smile:
Mark

Further thoughts: of course if you’re using Markdown, that would not be viable. I’m not so conversant with details of RegEx syntax, so am I right in thinking your \n\n$ only finds empty lines at the end of documents? If so, search for that and try putting \n or \n$ in the replace field (on a duplicate of the project to test it out!)

2 Likes

That’s a good point, and an even broader one than Markdown[1]. However this is done, with the menu command, regular searches or regex searches, bulk deleting empty lines could be a problem for anyone that uses an empty line as a minor section, or scene break. So that’s something to be cautious of. There is no symbol or way of saying this should only be done to the ends or beginnings of sections.

Anyway, searching and replacing aside, for those Mac users there is also the Edit ▸ Text Tidying ▸ Remove Empty Lines Between Paragraphs menu command, when run in Scrivenings mode. This will also remove empty lines between sections because of how scrivenings works on a Mac. Again though, this command will nuke scene breaks, but it is otherwise easier (and maybe slightly safer) to use than search & replace. Either way, back up a project before executing such a widespread alteration to the text.

It doesn’t work the same on Windows because Scrivenings isn’t a single unit of text, so the empty lines at the top and bottom of a document are not technically “between” anything.


Trivia: the dollar sign in regex stands for the end of a line up to the point of any marker that would end the line(like the pilcrow stands for), so that particular pattern would not really be significantly different than \n\n as we can be assured that the new line character, \n falls at the end of a line already (funnily enough!). You would use the dollar sign for cases where you want to find or change something all the way up to the very end of the line without the newline, and thus potentially accidentally merge two lines together with a replacement.


  1. Though it’s worth pointing out that with Markdown none of this matters in the slightest, so this isn’t really super important of an issue to begin with. You can have 54,000 empty lines between two paragraphs and it will clean that out for you automatically. ↩︎

3 Likes

Point absolutely taken for the rest. But is there no Unicode code-point/symbol for EOF that could be used to select only empty lines at ends of documents, because even using Scrivenings mode, is not every scene a discrete document as far as the operating system is concerned?

1 Like

There isn’t a conventional EOF marker or character that would be applicable to the text engine on either platform. From what I’ve found, some regex dialects do have support for scanning from the beginning or the end of the buffer, but none that work in Scrivener’s toolkit.[1] Even so, it would be a bit complicated by the point you bring up about how text in Scrivenings mode isn’t many multiple buffers or documents. The lines you see between sections are inserted graphics set to read-only, it truly is one file while you are working with it—at least at the level we’re talking about with search and replace. Internally Scrivener is of course aware of these divisions and where to put edits back into the right places.


  1. And the one I found may not even be an official regex dialect but something added on top of it, found in Notepad++ for Windows. ↩︎

1 Like

OK. I understand, so the real answer to Beppe’s oringinal post, is my reply. i.e. just ignore them in the editor (or remove them manually when you encounter them) and let the compiler deal with them at that point.

:slight_smile:
Mark

That’s certainly what I would do, and do (but again with Markdown you can be less uptight about WYSIWYG stuff like this and just write, but I digress, Scrivener’s toolkit goes a long way toward mitigating rich text editing’s issues).

1 Like