Alex
Alex

Reputation: 2800

Sublime text, search and replace to add new space in stylesheets

I am trying to find a way to search and replace in multiple files against the following situation:

.selector{

So that it becomes:

.selector {

Is there any regex or other method of finding a lack of space following by curly bracket?

Thanks.

Upvotes: 1

Views: 467

Answers (4)

Andriy Horen
Andriy Horen

Reputation: 2940

RegExp solution:

Match any non-whitespace character followed by curly bracket:

(\S)\{

Insert space in between of character and bracket, replace string:

$1 {

Upvotes: 0

Tushar
Tushar

Reputation: 87203

I'll recommend you to use https://packagecontrol.io/packages/HTML-CSS-JS%20Prettify package to format you HTML/CSS/JS code properly.

You can install this package using Package Control and configure it.

You'll first need to install Node.js to use this package.


If you want to use regex

Find ---- \b([.#\d\w-]*?)\{

Replace By ---- $1 {

Upvotes: 1

Praveen Kumar Purushothaman
Praveen Kumar Purushothaman

Reputation: 167182

I have done this. Use this:

Step 1: Find for { and replace with (space){.
Step 2: Now replace all (space)(space){ with (space){.

Note: Replace the (space) with a real space character.

Upvotes: 2

Axel Lavielle
Axel Lavielle

Reputation: 252

there is a replace method: http://sublime-text-unofficial-documentation.readthedocs.org/en/latest/search_and_replace/search_and_replace_files.html

Just cheat on it: First replace all '{' with ' {' (all brackets into one space) Then replace all ' {' with ' {' (double spaced into one space)

Upvotes: 0

Related Questions