Textmate Ruby Macro Remove Blank Lines

Textmate Ruby Macro Remove Blank Lines
#!/usr/bin/env ruby -wKU
STDIN.readlines.each {|e| print e unless e =~ /^\n/}

#Set Save "Nothing"
#Set Input "Selected Text" or "Character"
# and
#Set Output "Replace Selected Text"

Comments

nexusventuri said…
if you use \s* you can also remove blank lines containing spaces or tabs

#!/usr/bin/env ruby

example = "\naba\n\t\n\n\n \navccc"
example.each_line{ |line| print line unless line =~ /^\s*\n/

Popular posts from this blog

Vim vi how to reload a file your editing