Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sublime Text 2: Trim trailing white space on demand

I know that Sublime Text 2 can delete the trailing white space on files upon saving.

When working in a team and commiting a change to a file this tends to produce huge diffs which make peer code review more cumbersome. For that reason I prefer to only do the white space cleaning when I'm commiting huge changes to a file anyway and leave whitespace as it is for the minor changes.

I would like to know if there's any command for executing the trimming of the white space on demand on a file, other than "Activate trimming on save > Save file > Deactivate trimming".

Searching in the Documentation and on stackoverflow didn't show anything relevant, all the links seem to talk about the auto trimming on save.

like image 675
José Luis Avatar asked Sep 06 '12 09:09

José Luis


1 Answers

I use these steps for a quick on-demand solution within Sublime Text:

  1. Find > Replace...
  2. Find What: [ \t]+\n
  3. Replace With: \n
  4. Replace All

You could also do this for a large set of files via

  1. Find > Find in Files...
  2. Find: [ \t]+\n
  3. Where:
  4. Replace: \n
  5. Replace
like image 59
Jason Favors Avatar answered Sep 20 '22 15:09

Jason Favors