What locale does VIM use for sorting and regular expressions?

1

Suppose I have a file with the following content:

c
C
b
B
a
A

When I do :%sort, I get the following result:

A
B
C
a
b
c

When I do :%!sort (note the '!'), I get

a
A
b
B
c
C

I get the same behaviour with regular expressions, i.e. [A-Z] inside VIM matches uppercase characters and not [aAbBcC...].

The output of "locale":

LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_PAPER="en_US.UTF-8"
LC_NAME="en_US.UTF-8"
LC_ADDRESS="en_US.UTF-8"
LC_TELEPHONE="en_US.UTF-8"
LC_MEASUREMENT="en_US.UTF-8"
LC_IDENTIFICATION="en_US.UTF-8"
LC_ALL=

The output of :language inside VIM:

Current language: 
"LC_CTYPE=en_US.UTF-8;
LC_NUMERIC=C;
LC_TIME=en_US.UTF-8;
LC_COLLATE=en_US.UTF-8;
LC_MONETARY=en_US.UTF-8;
LC_MESSAGES=en_US.UTF-8;
LC_PAPER=en_US.UTF-8;
LC_NAME=en_US.UTF-8;
LC_ADDRESS=en_US.UTF-8;
LC_TELEPHONE=en_US.UTF-8;
LC_MEASUREMENT=en_US.UTF-8;
LC_IDENTIFICATION=en_US.UTF-8"

According to ":language" vim should be using "utf8 sorting", but apparently it doesn't.

Aton

Posted 2012-09-14T18:11:45.090

Reputation: 113

Answers

1

From VIM 7.3 ':help sort'

The details about sorting depend on the library function used.  There is no
guarantee that sorting is "stable" or obeys the current locale.  You will have
to try it out.

Jim

Posted 2012-09-14T18:11:45.090

Reputation: 101

0

(1) I know that this is not really an answer to the main question that was asked, and (2) I don't have access to vim right now, so all I can be sure of is that this works for vi.  That said, you can get vi to do case-insensitive searches by typing :set ignorecase (or :set ic for short, or :se ic for shorter).  Use :set noic to revert to case-sensitive behavior.

Scott

Posted 2012-09-14T18:11:45.090

Reputation: 17 653