DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

TextMate - Convert Tabs To 2 Spaces And Strip Whitespace

  • submit to reddit
        Command for TextMate (or any other editor really) to strip whitespace and convert tabs...
I only ever use 2 spaces so i've gone with that.

#!/usr/bin/env ruby do |line|
  line.sub!(/^(\t+)/) { |c| '  ' * c.length }
  line.sub!(/(\s+)$/, "\n")
  puts line