login
Notepad++ replace (with) line-break posted: Fri 2011-09-02 16:50:01 tags: npp, work
Fell in love with Notepad++ almost immediately when we met, but with so much power there's always bound to be something that falls short of total intuitivity. In today's instance, we had a block of comma-separated list elements with no line breaks, and we wanted to replace each comma with a comma and a line-break. Assuming a Windows environment, where the conventional line-break is actually two control characters in sequence: carriage-return (CR) and linefeed (LF), well-known to programmers as "CRLF".

When you Ctrl+F in Notepad++, it shows the Find dialog, and the next tab in that dialog interface is Replace. You need to make sure the "Search mode" option in the bottom-left is set to "Extended (\n, \r, \t, ...", and in the Replace spec, using the code "\r\n" would produce the necessary carriage-return + linefeed. You can get a better visual idea of how it accomplishes that by turning on line break visibility in View menu > Show Symbol > Show End of Line.

(Not so easy to remember, huh. Why \r\n? By old convention, "escaped-R" or \r represents (carriage) Return, and "escaped-N" or \n represents Newline.)