Sublime Forum

Ability to remove extra spaces between text?

#1

Besides using the find / replace tool, is there an automated way or perhaps a package that removes extra spacing in between words?

An example for clarifications sake:

How it currently is

 important     sectors such

How I would like it to be

important sectors such

Thanks in advanced for your help.

0 Likes

#2

Open the find-and-replace panel with “Ctrl+H”. Activate regular expressions with “Alt+R”.
Type in Find What: \s+
Type in Replace With: " " (one space without quotation mark)
Hit

If that’s too much work, you can create a plug-in that when you save the file performs the substitutions.

0 Likes

#3

Note that \s also matches newlines, so instead use \t]+ if you don’t want that (likely).

0 Likes

#4

Awesome, thanks for the help guys. That did the trick.

0 Likes

#5

Another option would be to match repeatable spaces, like so: \h{2,3}. For non regex guys here:

  • \h is any horizontal whitespace char (be it tab or space)
  • you match more than 2 spaces (you could also specify maximum amount, like {2, 4}, where you can match anything between 2 to 4 spaces)

Alternatively, you can match only spaces, like so: ^\S\n\t]{2,}

1 Like