37

可能重复:
如何在 Vim 中对数字和文字列进行排序

我必须根据线程 ID 对以下行进行排序。

Internal thread 0 bound to OS proc set {1}
Internal thread 1 bound to OS proc set {5}
Internal thread 2 bound to OS proc set {9}
Internal thread 10 bound to OS proc set {41}
Internal thread 9 bound to OS proc set {37}

当我发出:!sort -n它们时,它们会像这样排序:

Internal thread 0 bound to OS proc set {1}
Internal thread 1 bound to OS proc set {5}
Internal thread 10 bound to OS proc set {41}
Internal thread 2 bound to OS proc set {9}
Internal thread 9 bound to OS proc set {37}

但我需要它们像这样排序:

Internal thread 0 bound to OS proc set {1}
Internal thread 1 bound to OS proc set {5}
Internal thread 2 bound to OS proc set {9}
Internal thread 9 bound to OS proc set {37}
Internal thread 10 bound to OS proc set {41}
4

1 回答 1

65

只需使用 Vim 自己的排序功能。直观地突出显示文本(或使用范围)并键入:

:sort n

文档可在此处获得:http: //vim.wikia.com/wiki/Sort_lines

或者在 Vim 本身中::help sort

(编辑以反映 dash-tom-bang 的重要说明和对 Vim 自己的帮助文件的引用。)

于 2012-12-28T21:57:14.093 回答