Using Text Replacements With New Lines In Notepad++

Notepad++ is a free power user’s text editor for Windows. It is more or less standard to have if you do any sort of code hacking, be it for CSS, PHP or whatever you need a superior text editor for.

One function that everybody needs to know how to use in a text editor is replace. There will be times when you will want to replace text with the addition of a new line (i.e. "replace X with Y and press enter once").

The way to do this in Notepad++ is easy once you know how it’s done.

Let’s say you have this:

npp1

..and you wanted to search-and-replace so that each instance of "This is a test." was on a separate line.

Press CTRL+H for the replace function, and fill out as follows:

npp2

Next to Find what, I enter a period because that’s where I want the line break to occur. Next to Replace with I enter that same period (because I want it to stay there and not be removed), followed by \r.

On the bottom, I tick the option for Extended (\n, \r, \t, \0, \x…) so the \r will work.

After that, I click Replace All in the same window.

What happens is this:

npp3

NPP tells me how many occurrences were replaced, and then my final result is this:

npp4

NPP found the period, and for each replaced it with a period followed by a new line.

Important things to know

The \r switch will work anywhere, so if you wanted NPP to add a new line before the replacement text, just place \r the beginning instead of the end.

You can in fact search for things like single blank spaces and replace them with new lines. For example, if you open up an old text file that has a bunch of improperly formatted text flying all over the place, you can search for two spaces, replace with \r, and on every instance of a double-space NPP will replace with a new line.

Knowing how to do this will save you lots of time if you use NPP frequently.

Free eBook!

Like what you read?

If so, please join over 28,000 people who receive our exclusive weekly newsletter and computer tips, and get FREE COPIES of 5 eBooks we created, as our gift to you for subscribing. Just enter your name and email below:

Post A Comment Using Facebook

Discuss This Article (Without Facebook)

2 comments

  1. Is there a reason why you say “/r” in two in places in the article when in the picture example and the “Extended options” step you have “r” entered?

  2. Goof on my part. I’ll fix after I write this reply.

Leave a Reply to Rich

PCMech Insider Cover Images - Subscribe To Get Your Copies!
Learn More
Every week, hundreds of tech enthusiasts, computer owners
and geeks read The Insider, the digital magazine of PCMech.

What’s Your Preference?

Daily Alerts

Each day we send out a quick email to thousands of PCMECH readers to notify them of new posts. This email is just a short, plain email with titles and links to our latest posts. You can unsubscribe from this service at any time.

You can subscribe to it by leaving your email address in the following field and confirming your subscription when you get an email asking you to do so.

Enter your email address for
Daily Updates:

Weekly Newsletter

Running for over 6 years, the PCMECH weekly newsletter helps you keep tabs on the world of tech. Each issue includes news bits, an article, an exclusive rant as well as a download of the week. This newsletter is subscribed to by over 28,000 readers (many who also subscribe to the other option) - come join the community!

To subscribe to this weekly newsletter simply add your email address to the following field and then follow the confirmation prompts. You will be able to unsubscribe at any time.

Enter your email address for
Free Weekly Newsletter: