Replace \n with actual new line in Sublime Text
How can I replace
\n in Sublime Text with real in-editor displayed new line so:
in the editor when I view the file in it.
Turn on Regex Search and Replace (icon most to the left in search and replace bar or shortcut Alt + R)
Find > Replace, or (Ctrl+H), to open the
Replace With Window, and use Ctrl+Enter to indicate a new line in the
Replace With inputbox.
Read more... Read less...
Fool proof method (no RegEx and Ctrl+Enter didn't work for me as it was just jumping to next
First, select an occurrence of
\n and hit Ctrl+H (brings up the
Replace... dialogue, also accessible through
Find -> Replace... menu). This populates the
Find what field.
Go to the end of any line of your file (press End if your keyboard has it) and select the end of line by holding down Shift and pressing → (right arrow) EXACTLY once. Then copy-paste this into the
Replace with field.
(the animation is for finding true new lines; works the same for replacing them)
In Sublime Text (with shortcuts on Mac):
Highlight the text that you want to search to apply Find & Replace
Go to Menu > Find > Replace... (Keyboard Shortcut: Alt + Command + F)
In the Find & Replace tool, enable Regular Expression by clicking on the button which looks like [.*] (Keyboard Shortcut: Alt + Command + R)
In Find What, type:
Note: The additional
\escapes the Regular Expression syntax when searched.
In Replace With, type:
Click on the 'Replace All' button (Keyboard Shortcut: CTRL + Alt + Enter)
Your literal text
\n will then turn into an actual line break.
On Windows, Sublime text,
You press Ctrl + H to replace \n by a new line created by Ctrl + Enter.
Replace : \n
By : (press Ctrl + Enter)
None of the above worked for me in Sublime Text 2 on Windows.
I did this:
- click on an empty line;
- drag to the following empty line (selecting the invisible character after the line);
- press ctrl+H for replace;
- input desired replacement character/string or leave it empty;
- click "Replace all";
By selecting before hitting ctrl+H it uses that as the character to be replaced.
What I did is simple and straightforward.
\n or whatever you want to find to Find.
Find All at right bottom corner, this will select all results.
enter on your keyboard and it will break all selected into new lines.