---
title: Sort Lines Alphabetically In Vim
teaser:
tags: vim
author: Dan Croak
published_on: 2013-02-01
---

Imagine you're working in vim. You come across this code:

    gem 'clearance', '1.0.0.rc4'
    gem 'neat'
    gem 'stripe'
    gem 'pg'
    gem 'thin'
    gem 'rails', '3.2.11'
    gem 'bourbon'
    gem 'simple_form'
    gem 'strong_parameters'

You want to sort the list alphabetically. You select the lines visually:

    Shift + V

You invoke the `sort` function:

    :sort

You rejoice:

    gem 'bourbon'
    gem 'clearance', '1.0.0.rc4'
    gem 'neat'
    gem 'pg'
    gem 'rails', '3.2.11'
    gem 'simple_form'
    gem 'stripe'
    gem 'strong_parameters'
    gem 'thin'

You dig deeper:

    :help sort

## What's next

If you found this useful, you might also enjoy:

* [Wrap Existing Text at 80 Characters in Vim][wrap]
* [Onramp to Vim][onramp]

[wrap]: https://thoughtbot.com/blog/wrap-existing-text-at-80-characters-in-vim
[onramp]: https://thoughtbot.com/upcase/onramp-to-vim
