30

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
  • 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
  • @FDinoff, yep, thanks for reporting the typo :) – sampablokuper Aug 10 '14 at 0:23
43

Vim's own :sort command

:%sort i

does what you want.

See :help :sort.

But you can use your system's sort command as a filter:

:%!sort -f

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

  • 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

Not the answer you're looking for? Browse other questions tagged or ask your own question.