55

Vim's default sort is case sensitive, and produces results like this:

A
B
a

How can it be made case-insensitive, to produce the following result given the same input?

A
a
B
2
  • what about to use sort -f eventually redirecting output to a new file sort -f old_file > new_file? – Hastur Aug 7 '14 at 13:32
  • I assume you mean case sensitive in the first one? – FDinoff Aug 7 '14 at 23:40
76

Vim's own :sort command

:%sort i

does what you want.

See :help :sort.

Alternatively, you can also use your system's sort command as a filter:

:%!sort -f

See :help filter in Vim and $ man sort in your shell.

2
  • What's different between :%sort i and :sort i? – Deqing Jul 5 '18 at 5:16
  • 1
    No fundamental difference. The former is explicit about the range on which it operates on while the latter is implicit. – romainl Jul 5 '18 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy