views:

4493

answers:

3

Does anyone know how to delete a line using Find & Replace in Notepad++ ?

In my Find query it finds the proper lines okay: ^.pPrev.$ In the Replace field, I leave it blank thinking the line should deleted (i.e. replaced with nothing), but the newline and endline characters remain.

A: 

Not sure about Notepad++, but you can always do it with gVim. The command is like this:

%g/^.pPrev.$/d

You can download gVim here if you don't have it already.

JJ
+5  A: 

Use the "Extended" setting in the Replace window (not "Regular expression": I'm sure there's a way to do it with Regular expression, but using "Extended" works fine).
Enter ".pPrev.\r\n" in the "Find what" field, and leave the "Replace what" field blank. This will include the \r\n characters in the match and delete the whole line.

Donut
A: 

The general principle whichever editor you're using is that you need to include the new line characters (\r\n assuming Windows line endings) in your search so that they will be included in the replacement and thus removed.

In Notepad++ this is made a bit more confusing by the 2 different search and replace commands. See this Wiki page for details: Replacing Newlines in Notepad++

I only had an old version of Notepad++ to hand so had to use Extended Search (accessed via ^R), making sure Regular Expr was unticked and using ^M to insert the new line character into the Find field. However if you make sure you're using Notepad++ 4.9 or later you should be able to use \r and \n in the regexp mode.

mikej