如何在Vim中对UTF-8行进行排序? [英] How to sort UTF-8 lines in Vim?
问题描述
我在Vim中有以下几行:
I have these lines in Vim:
a
c
b
e
é
f
g
当我执行:%sort
时,我得到了:
and when I do :%sort
, I get this:
a
b
c
e
f
g
é
显然,é"行不应位于结尾,而应位于"e"行之后.有可能让Vim正确地对这些行进行排序?不是将ASCCI键用于字符,而是实际的字符.
Obviously, the "é" line should not be at the end, it should be after the "e" line. Is it possible to get Vim to sort these lines correctly? Not using the ASCCI key for the characters but the actual character.
我也尝试了:!sort
(使用GNU sort
实用程序),但是得到了相同的结果.
I also tried with :!sort
(to use GNU sort
utiliy) but I get the same result.
推荐答案
:%sort
和:%!sort
不一定以相同的方式工作.引用:help sort
:
:%sort
and :%!sort
do not necessarily work in the same way. To quote :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.
另一方面,GNU会根据当前语言环境进行排序.引用man sort
:
On the other hand, GNU sort sorts according to the current locale. To quote man sort
:
*警告* 环境指定的语言环境会影响 排序.设置LC_ALL = C以获取使用的传统排序顺序 本机字节值.
* WARNING * The locale specified by the environment affects sort order. Set LC_ALL=C to get the traditional sort order that uses native byte values.
在我的系统上(临时设置了fr_CA.UTF-8的Ubuntu 9.10):%sort
就像设置了C
或POSIX
一样进行排序,而:%!sort
则根据法语语言环境进行了排序.
On my system (Ubuntu 9.10 with fr_CA.UTF-8 temporarily set) :%sort
sorts as if C
or POSIX
was set, while :%!sort
sorts according to the French locale.
我的猜测是,您最初在类似POSIX的语言环境下尝试了:%sort
和:%!sort
(产生了相同的结果),然后仅使用:%sort
继续进行了不同语言环境的实验(始终返回类似POSIX的订单).你能确认吗?
My guess is that you've initially tried both :%sort
and :%!sort
under a POSIX-like locale (which yielded the same result), and then continued your experiments with different locales using :%sort
only (which always returned POSIX-like order). Can you confirm that?
这篇关于如何在Vim中对UTF-8行进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!