Find and Replace String with a New Line in Notepad++

Notepad++ is a source code and text editor that is mostly used by programmers to edit their codes in an easy environment. This is the advanced version of default Notepad and it supports several languages. There are many features and tools that users can use to edit their source code or text. Sometimes users will require adding new lines in their existing text file. However, there are different options that are required to set before trying to replace them with the new lines. In this article, we will teach you about how you can add new lines in Notepad++ by using the Find and Replace tool.

Find and Replace in Notepad++

Replacing String/Character/Symbol with a New Line

Depending on the type of text or source code, it may have different strings, characters, or symbols. There are different reasons that a user will require adding new lines after a specific string in Notepad++. The find and replace in Notepad++ is similar to the most text editors that provide this tool. However, there are some extra options within the Notepad++, which can help in identifying different kinds of characters or symbols. We are going to use the replace all option in the below steps, however, you can also use the find next and replace a single string for a new line. You can follow the below steps to try it out:

  1. Open Notepad++ by double-clicking on the shortcut or searching it through the Windows search feature.
  2. Click on the File menu in the menu bar, choose the Open option to open an existing file, or choose the New to create a new file, and add text in it.
     
    Opening an existing file or creating a new file
  3. Now click on the Search menu in the menu bar and choose the Replace option. You can also hold the Ctrl key and press H to open the Replace window through shortcut keys.
    Opening the replace window
  4. For the string, add the word in ‘Find what‘ box and replace it by adding the ‘\r\n‘ before or after the word as shown below. Make sure you select the Extended for Search Mode.
    Note: You can also only use the ‘\n‘ rather than using the ‘\r\n‘.

     
    Adding the new lines by replacing strings
  5. Click on the Replace All button to add new lines before or after the string, depending on where you want the new lines.
  6. For the symbol, you just need to add the symbol in the first box and again add the next line command with a symbol in the second box. Click on the Replace All button.
    Adding the new lines by replacing the symbol
  7. Now for the character, add the character in the first box of Replace tab and the new line command with character in the second box as shown below. Then click the Replace All button to add new lines before the character. Make sure you select Match case and Match whole word only options.
    Adding new lines by replacing a single character
ABOUT THE AUTHOR

Kevin Arrows


Kevin Arrows is a highly experienced and knowledgeable technology specialist with over a decade of industry experience. He holds a Microsoft Certified Technology Specialist (MCTS) certification and has a deep passion for staying up-to-date on the latest tech developments. Kevin has written extensively on a wide range of tech-related topics, showcasing his expertise and knowledge in areas such as software development, cybersecurity, and cloud computing. His contributions to the tech field have been widely recognized and respected by his peers, and he is highly regarded for his ability to explain complex technical concepts in a clear and concise manner.