[sublimetext2] 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:

foo\nbar

becomes:

foo
bar

in the editor when I view the file in it.

This question is related to sublimetext2 sublimetext sublimetext3

The answer is


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

Cheers


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.


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.


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.


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.


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


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


For Windows line endings:

(Turn on regex - Alt+R)

Find: \\r\\n

Replace: \r\n

illustration


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)


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


  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

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


Examples related to sublimetext2

Is there a way to view two blocks of code from the same file simultaneously in Sublime Text? How to Install Sublime Text 3 using Homebrew 80-characters / right margin line in Sublime Text 3 Comparing the contents of two files in Sublime Text What is the default font of Sublime Text? Showing the same file in both columns of a Sublime Text window What is the difference between Sublime text and Github's Atom Sublime Text 2 multiple line edit Set Encoding of File to UTF8 With BOM in Sublime Text 3 Regex replace uppercase with lowercase letters

Examples related to sublimetext

Sublime text 3. How to edit multiple lines? Why do Sublime Text 3 Themes not affect the sidebar? How to Install Sublime Text 3 using Homebrew 80-characters / right margin line in Sublime Text 3 Comparing the contents of two files in Sublime Text What is the default font of Sublime Text? Showing the same file in both columns of a Sublime Text window Sublime Text 3, convert spaces to tabs What is the difference between Sublime text and Github's Atom Sublime Text 2 multiple line edit

Examples related to sublimetext3

Sublime text 3. How to edit multiple lines? How to open remote files in sublime text 3 Eslint: How to disable "unexpected console statement" in Node.js? Why do Sublime Text 3 Themes not affect the sidebar? How to Install Sublime Text 3 using Homebrew How to change background and text colors in Sublime Text 3 80-characters / right margin line in Sublime Text 3 What is the default font of Sublime Text? Column/Vertical selection with Keyboard in SublimeText 3 How to compile and run C in sublime text 3?