Replace \n with actual new line in Sublime Text

Sublimetext2SublimetextSublimetext3

Sublimetext2 Problem Overview


How can I replace \n in Sublime Text with real in-editor displayed new line so:

foo\nbar

becomes:

foo
bar

in the editor when I view the file in it.

Sublimetext2 Solutions


Solution 1 - Sublimetext2

Turn on Regex Search and Replace (icon most to the left in search and replace bar or shortcut Alt + R)

Find What: \\n
Replace with: \n

Solution 2 - Sublimetext2

Use Find > Replace, or (Ctrl+H), to open the Find What/Replace With Window, and use Ctrl+Enter to indicate a new line in the Replace With inputbox.

Solution 3 - Sublimetext2

Fool proof method (no RegEx and Ctrl+Enter didn't work for me as it was just jumping to next Find):

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)

enter image description here

Solution 4 - Sublimetext2

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)

Solution 5 - Sublimetext2

In Sublime Text (with shortcuts on Mac):

  1. Highlight the text that you want to search to apply Find & Replace

  2. Go to Menu > Find > Replace... (Keyboard Shortcut: Alt + Command + F)

  3. In the Find & Replace tool, enable Regular Expression by clicking on the button which looks like [.*] (Keyboard Shortcut: Alt + Command + R)

  4. In Find What, type: \\n

    Note: The additional \ escapes the Regular Expression syntax when searched.

  5. In Replace With, type: \n

  6. Click on the 'Replace All' button (Keyboard Shortcut: Ctrl + Alt + Enter)

Your literal text \n will then turn into an actual line break.

Solution 6 - Sublimetext2

What I did is simple and straightforward.

Enter Space or \n or whatever you want to find to Find.

Then hit Find All at right bottom corner, this will select all results.

Then hit enter on your keyboard and it will break all selected into new lines.

Solution 7 - Sublimetext2

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.

Solution 8 - Sublimetext2

On Mac, Shift+CMD+F for search and replace. Search for \n and replace with Shift+Enter.

Solution 9 - Sublimetext2

  1. Open Find and Replace Option ( Ctrl + Alt + F in Mac )
  2. Type \n in find input box
  3. Click on Find All button, This will select all the \n in the text with the cursor
  4. Now press Enter, this will replace \n with the New Line

Solution 10 - Sublimetext2

For Windows line endings:

(Turn on regex - Alt+R)

Find: \\r\\n

Replace: \r\n

illustration

Solution 11 - Sublimetext2

On MAC:

Step 1: Alt + Cmd + F . At the bottom, a window appears
Step 2: Enable Regular Expression. Left side on the window, looks like .*
Step 3: Enter text to you want to find in the Find input field
Step 4: Enter replace text in the Replace input field
Step 5: Click on Replace All - Right bottom.

replace field

Solution 12 - Sublimetext2

The easiest way, you can copy the newline (copy empty 2 line in text editor) then paste on replace with.

Solution 13 - Sublimetext2

ctrl+h

sample : type: replace: \n

down below , find button - change to ALT+R you see changed eFFect in color , better to use sample

nice feature

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionleemourView Question on Stackoverflow
Solution 1 - Sublimetext2chrisg86View Answer on Stackoverflow
Solution 2 - Sublimetext2SashView Answer on Stackoverflow
Solution 3 - Sublimetext2Ciprian TomoiagăView Answer on Stackoverflow
Solution 4 - Sublimetext2nhnminhView Answer on Stackoverflow
Solution 5 - Sublimetext2allisondevView Answer on Stackoverflow
Solution 6 - Sublimetext2Feng LiuView Answer on Stackoverflow
Solution 7 - Sublimetext2pidView Answer on Stackoverflow
Solution 8 - Sublimetext2Joris WeimarView Answer on Stackoverflow
Solution 9 - Sublimetext2Hassan MudassirView Answer on Stackoverflow
Solution 10 - Sublimetext2jntView Answer on Stackoverflow
Solution 11 - Sublimetext2Venkat ChowdaryView Answer on Stackoverflow
Solution 12 - Sublimetext2Peternak Kode ChannelView Answer on Stackoverflow
Solution 13 - Sublimetext2HIZIRView Answer on Stackoverflow