对文本中的特定行进行排序

che*_*run 2 sorting vi vim emacs nano

我有给定的文字:

# Blub
Hello this is a blub text.

# Bla
This is the bla text.

# Abba
Another text.
Run Code Online (Sandbox Code Playgroud)

有可能用#?对线条进行排序?这样生成的文本是:

# Abba
Another text.

# Bla
This the bla text.

# Blub
Hello this is a blub text.
Run Code Online (Sandbox Code Playgroud)

最好使用vim或emacs.

hua*_*uan 5

在Emacs,

  1. M-xsort-regexp-fields
  2. 输入: #[^#]*
  3. 输入: \&

第一个正则表达式用于分隔记录,第二个正则表达式用于排序.

如果您可以自由选择标记字符而*不是使用#,则可以使用org-mode命令org-sort-entries,这样可以避免进入正则表达式.