Sort gems in your Gemfile
Select gems in the Gemfile and sort them
:'<,'>!sort
Written by Alex G
Related protips
8 Responses

oO
This assumes three things:
1) You're not using any group
blocks
2) Your gems do not have require order dependencies (client_side_validations
and its plugins come to mind)
3) You want your gems sorted rather than organized by similarity.

Make sure you understand what does '<,'> mean ;)

Yes, I know what '<,'>
means @cutalion. So you're suggesting sorting subsets of gems. No problem, my rules to the subsets you can select/sort. I'm just saying it's dangerous... use with caution :)

Why would you want to sort your Gems? Usually (as pointed out above) they're in groups. Sometimes they're also sorted according to purpose.

@descentintomael, why not? I found it quite handy to have sorted groups of gems in large Gemfile.
For instance, take a look at catarse project's Gemfile
and at the version with sorted gems in groups. At the first sight there is no difference, but I believe that the additional rule (or convention) reduces the chaos in that file. Of course it should be a team decision.

That makes sense. I thought your original idea was to sort all the gems in the top-level of the Gemfile.

If you just need a sorted list of all your gems, you can try this script http://rbjl.net/63-what-s-in-your-gemfile with the --sorted option

@janlelis, nice script! Not sure I'll use it to keep a sorted list of gems - it adds a lot of noise to Gemfile. Overall, I like it, it could save some time.