How to remove line break and all spaces on the next line in sublime text editor?

51,603

Solution 1

  1. open Search and replace (CTRL+H)
  2. enable "Regular Expression" (circled in red)
  3. enter \n\s+ in the search field, clear the replace field
  4. press "Replace all"

enter image description here

This will remove all newlines (\n+) followed by all whitespace (\s+) in the next line.

Solution 2

In your Sublime Text user settings, you can specify the following to trim trailing white space.

"trim_trailing_white_space_on_save": true

You might want to have a look at the Trimmer that has a couple of options to trim whitespace.

Solution 3

you can also use \n+ to remove all the unwanted space , if you want to use a single line then replace with \n online

Share:
51,603
shekhardtu
Author by

shekhardtu

By Day: A usual guy with unusual job timing :p By Nights: Eat... Sleep... Code... Eat... Sleep For Fun: Quora, Tinder, nearbuy and Foosball

Updated on November 17, 2021

Comments

  • shekhardtu
    shekhardtu over 2 years

    It happens many times when we need to remove line end and unnecessary space between the HTML element. So this could be proven as a time-saving technique.

  • Gerald Schneider
    Gerald Schneider over 6 years
    Note that when using Replace all it doesn't make any difference if you use \n+ or \n. Also, using this will remove all line breaks, reducing the file to a single line.
  • johnrao07
    johnrao07 about 6 years
    awesome, thanks! just replace with a "space" for a space between words!