Search and replace with carriage return in Notepad++

Notepad++ is an excellent text editor, often refer to as Notepad for power users. Based on the powerful editing component Scintilla, it offers all kinds of advanced features like syntax highlighting and tabbed browsing.

This article will show you how to do advanced search and replace in Notepad++ with the carriage return character.

Once you're comfortable with this, you should know that Notepad++ also supports full regular expression. Understanding regex will allow you to do all sorts of nifty editing which might come in handy when you encounter certain task.

What is a carriage return character used for

CR and LF are control characters or bytecode that can be used to mark a line break in a text file.

  • CR, short for Carriage Return tells the viewer to moves the cursor to the beginning of the line without advancing to the next line.
  • LF, short for Line Feed moves the cursor down to the next line without returning to the beginning of the line.

A stand-alone CR is equivalent to pressing Enter followed by Return key.

A CR immediately followed by a LF (CRLF, \r\n, or 0x0D0A) moves the cursor down to the next line and then to the beginning of the line.

TL;DR : On Windows, the standard escape code for a new line is CRLF. On the other hand, Unix-based systems simply uses LF to indicate a new line.

Enable search and replace support for carriage return character

To be able to search for and replace a carriage return in Notepad++, you have to select Extended search mode.

Enable search and replace support for carriage return character

  1. Open up Notepad++.
  2. Select Search > Find (Ctrl + F) or Select > Replace (Ctrl + H) depending on your need.
  3. In Search Mode, change the radio box to Extended.

Replace carriage return character

Let's suppose we have a file with the content below :

1, 2, 3, 4, 5

and we want to convert it into

1
2
3
4
5

As you can see, numbers are separated by a comma and one space. So we need to replace ", " (without quotation mark) with a new line character. Obviously we are working on Windows, so a new line is equivalent to \r\n.

Replace carriage return character

  1. Open up Notepad++
  2. Select Search > Find (Ctrl + F) or Select > Replace (Ctrl + H) depending on your need.
  3. In Search Mode area, change the radio box to Extended.
  4. Tick Wrap around option.
  5. Type ", " (without quotation mark) into Find what box
  6. Type "\r\n" (without quotation mark) into Replace with box
  7. Click Replace All button once to replace all occurrences in the document.
Click to rate this post!
[Total: 18 Average: 5]

Leave a Comment