Сортировка численно в редакторе VI
Возможный дубликат:
Как отсортировать числовые и буквенные столбцы в Vim
Мне нужно отсортировать строки ниже на основе идентификатора потока.
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
Просто используйте функцию сортировки Vim. Визуально выделите текст (или используйте диапазон) и введите:
:sort n
Документация доступна здесь: http://vim.wikia.com/wiki/Sort_lines
Или в самом Vim: :help sort
(Отредактировано, чтобы отразить важный момент разъяснения от dash-tom-bang и ссылку на собственный файл справки Vim.)