I had the same problem and the solution proposed by Ƭᴇcʜιᴇ007 is ok for certain text encoding EOL (end of line) usually targeted to a specific OS platform.
So depending on what operative system you are targeting you can use alternatively one of the following:
- Alt + 013 that is equivalent to \r, as specified in Ƭᴇcʜιᴇ007 answer (usually for Mac);
- Alt + 010 that is equivalent to \n (usually for Unix / Lilnux);
- Alt + 013 and Alt + 010 if you want to insert both \r\n chars (for Win).
Using for the wrong EOL char for example Alt + 013 that means \r in case you are targeting a different OS platform you might have the need to convert the end of line chars to the correct type used in that platform where your code will run. In case you need to do so go to Menu > Edit > EOL Conversion (End Of Line Conversion) and from the sub menu choose the right platform your code is targeted to.
Also if you want you can assign to your preferred EOL conversion command a keyboard shortcut.
A further and more complex alternative would be to implement a macro to find and replace a customized placeholder when you are coding.
- Start recording a new macro;
- Recall the find and replace dialog;
- Insert into the "Find" field a char that you never use, for example in
my case I used the section symbol "§";
- Insert into the "Replace" field the newline char accordingly with
the used OS platform, in my case it is "\r\n";
- Into the find and replace window, check the "Extended" check
box. This way n++ will interpret correctly the \r\n
transforming it into the new line symbol: if you don't check
this option n++ inserts just \r\n, literally into the text;
- Press the replace all button;
- Stop macro recording;
- Save the macro and assign to it an unused keyboard shortcut (for ex. Alt+Enter).
The code of the macro is as the following:
<Macro name="Replace § with newline" Ctrl="no" Alt="yes" Shift="no" Key="13">
<Action type="3" message="1700" wParam="0" lParam="0" sParam="" />
<Action type="3" message="1601" wParam="0" lParam="0" sParam="§" />
<Action type="3" message="1625" wParam="0" lParam="1" sParam="" />
<Action type="3" message="1602" wParam="0" lParam="0" sParam="\r\n" />
<Action type="3" message="1702" wParam="0" lParam="768" sParam="" />
<Action type="3" message="1701" wParam="0" lParam="1609" sParam="" />
Of course it is possible to set the "find" field into find and replace with different char instead the § and a different EOL - newline char (the string literal \r\n) into the replace field to adapt it to the operative system platform that you have to target your code.
You can place the macro into the shorcuts.xml file into the notepad++ directory.
Once the macro is saved, how to use it:
1. Press Ctrl and click with the mouse a usual into the multiple points where you want to insert the new line;
2. Insert the § symbol or the one you choose as placeholder;
3. Use the appropriate key combination to activate the macro (in my case Alt+Enter);
4. The macro replaces all occurrence of the placeholder "§" with "\r\n" (or anything you've chosen to).
In synthesis you have to press first Shift + § and then Alt + Enter
Advantages: all proposed solutions work on all platforms, (take care of changing the EOL char accordingly!);
The Macro solution has the disadvantage that you have to choose one char placeholder symbol you don't use for anything else.
What to choose is a question of personal preferences.