Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove/Add Line Breaks after Specific String using Sublime Text

Using Sublime Text 2 - Is it possible to insert a line break/text return after a specific String in a text file e.g. by using the FindReplace tool?

(Bonus question: Is it possible to remove all line breaks after a specific String)

like image 384
Bernd Avatar asked Oct 25 '12 09:10

Bernd


People also ask

How do I get rid of extra lines in Sublime Text?

Press: Ctrl + H on PC, or. Command + Alt + F on Mac or.

How do you remove a line break in a string?

Use the String. replace() method to remove all line breaks from a string, e.g. str. replace(/[\r\n]/gm, ''); . The replace() method will remove all line breaks from the string by replacing them with an empty string.

How do I insert a line break in sublime?

To insert a new line below the current line in your code, hit Cmd–Return (Mac) or Ctrl–Enter(Windows).


2 Answers

Here's how you'd do it on a Mac:

Command+F > type string > Control+Command+G > ESC > Right Arrow > line break


and Windows/Linux (untested):

Control+F > type string > Alt+F3 > ESC > Right Arrow > line break


The important part being Control+Command+G to select all matches.
Once you've selected the text you're looking for, you can use the provided multiple cursors to do whatever text manipulation you want.

Protip: you can manually instantiate multiple cursors by using Command+click (or Control+click) to achieve similar results.

like image 143
Sara Avatar answered Sep 17 '22 13:09

Sara


Using the Find - Replace tool, this can be accomplished in two different ways:

  1. Click in the Replace field and press Ctrl + Enter to insert a newline (the field should resize but it doesn't, so it is hard to see the newline inserted).

  2. Inside the Find - Replace tool, activate the S&R regex mode (first icon on the left .*, keyboard shortcut is Alt + Ctrl/Cmd + R to activate/deactivate it).

  3. Type \n in the Replace field wherever you want to insert a newline.

Both solutions also work if you want to find newlines, just do it in the Find field.

like image 20
veducm Avatar answered Sep 21 '22 13:09

veducm