给定一个看起来像这样的文件:
Crab
some text that doesn't need sorting.
more textual descriptination
Albatross
some text or other
perhaps a list that needs no sorting:
1. a
2. bee
Dolphin
Pterodactyl
long story about this particular animal.
Run Code Online (Sandbox Code Playgroud)
我如何告诉 Vim(第 7 版)按动物名称的字母顺序对这个文件进行排序?不可能的?否则如何对这个文件进行排序?
是的,你可以在 vim 中做到:
:%s/$/$/
:g/^\w/s/^/\r/
:1del t | $put t
:g/^\w/,/^$/-1join!
:sort
:%s/\$/\r/g
:g/^$/d
Run Code Online (Sandbox Code Playgroud)
输出
Albatross
some text or other
perhaps a list that needs no sorting:
1. a
2. bee
Crab
some text that doesn't need sorting.
more textual descriptination
Dolphin
Pterodactyl
long story about this particular animal.
Run Code Online (Sandbox Code Playgroud)
您应该使用特殊字符来表示 EOL(除了$)!
| 归档时间: |
|
| 查看次数: |
950 次 |
| 最近记录: |