Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can you reformat text in TextMate

Is there a command in TextMate to re-indent or format text in a file?

I use this all the time in IDE's after pasting in a block of code, removing a block, etc for re-indenting a file.

Bonus points if there is a way to pretty indent, turning this:

has_many :users, :class_name => 'Users', :dependent => :destroy
has_many :comments, :class_name => 'Comments', :dependent => :destroy

into this:

has_many :users,    :class_name => 'Users',    :dependent => :destroy
has_many :comments, :class_name => 'Comments', :dependent => :destroy

But even just simple reformatting would be awesome.

Not sure if it matters but I'm mostly talking about Ruby-on-Rails apps here.

like image 476
Brian Armstrong Avatar asked Jul 10 '10 20:07

Brian Armstrong


1 Answers

Sweet!

This bundle adds it for Ruby code: http://github.com/mocoso/code-beautifier.tmbundle#readme

It only indents Ruby code (not HTML or anything else), and doesn't do the pretty indent (only regular indenting), but still - it re-indents the whole file with one command.

Edit: just realized another way to do it with a built in TextMate feature. option-apple-[ This indents one line. So if you do ctrl-a (to select all) and then option-apple-[ it has a similar effect (although it's two commands instead of one, and loses where you had the cursor)

like image 62
Brian Armstrong Avatar answered Sep 28 '22 23:09

Brian Armstrong