2012-12-28 18 views
15

可能性の重複:
How to sort numeric and literal columns in Vimソート数値VIエディタで

私はスレッドIDに基づいて、以下の行をソートする必要があります。私は:!sort -nを発行すると

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} 

彼らは次のように並べ替えられます:

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} 
+6

あなたの場合、 '%%sort -n -k 3' –

+0

@MichaelBerkowski:ありがとう、それは完璧に動作します。私がそれを受け入れるためにこれを答えとして提供してください。私はオプション 'n'と' 3'を理解しています。しかし、なぜ私は余分な '-k'が必要なのでしょうか? 'n'は数値ソートには不十分です – arunmoezhi

+0

' -k 3'は第3フィールドを明示的にソートします。 – sebnukem

答えて

26

ただ、Vimの独自のソート関数を使用します。重要な点を反映するために編集された(:help sort

:ドキュメントがここにあります

:sort n

http://vim.wikia.com/wiki/Sort_lines

あるいはVimの自体で視覚的にテキストをハイライト(または範囲を使用)とタイプdash-tom-bangの解明とVim自身のヘルプファイルへの参照)

+1

ここで大きな違いがあるのはダッシュを削除したものではなく、外部アプリケーションを呼び出す代わりにVimに組み込まれている機能を使用している点です( '!'がないことに注意してください)。ドキュメントはVimでも利用できます。 ':help:sort' –

+0

これは重要な説明です。ありがとう! – Nate

+1

あなたの意見はより顕著になるほど重要だと思うので、私は自分の答えを編集しました。 – Nate

関連する問題