shekhardtu
shekhardtu

Reputation: 5370

How can I remove a line break and all spaces on the next line in the Sublime Text editor?

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

Upvotes: 38

Views: 71608

Answers (4)

Mihalich
Mihalich

Reputation: 1

always trim on saving for sublime 4 (build 4169)

in Preferences.sublime-settings use two params:

"trim_trailing_white_space_on_save": "all",
"trim_only_modified_white_space": false,

Upvotes: 0

Munna Kumar
Munna Kumar

Reputation: 545

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

Upvotes: 4

idleberg
idleberg

Reputation: 12882

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.

Upvotes: 8

Gerald Schneider
Gerald Schneider

Reputation: 17797

  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.

Upvotes: 86

Related Questions