在VI编辑器中按数字排序

时间:2012-12-28 21:51:48

标签: vim text-editor vi

  

可能重复:
  How to sort numeric and literal columns in 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}

1 个答案:

答案 0 :(得分:38)

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

:sort n

此处提供了文档:http://vim.wikia.com/wiki/Sort_lines

或者在Vim本身::help sort

(编辑反映了破折号的重要澄清点以及对Vim自己的帮助文件的引用。)