Markdown 中的排序/反转部分(使用 VIM)

Sun*_*ang 5 sorting vim markdown reverse text

我有一个用于记录的 Markdown 文件。每个部分都有一个标题,按日期按时间顺序命名。该文件的部分内容如下。

## 20200628
- Traceback
- [x] code debug
- [x] read Section 2

## 20200629
- Homepage rebuilding

## 20200630
- 13:00: Meeting Tom
Run Code Online (Sandbox Code Playgroud)

我想以相反的方式对日志进行排序,之后它将显示如下。

## 20200630
- 13:00: Meeting Tom

## 20200629
- Homepage rebuilding

## 20200628
- Traceback
- [x] code debug
- [x] read Section 2
Run Code Online (Sandbox Code Playgroud)

我本来希望使用 VIM,但我不知道实现此目的的正确方法是什么。任何建议将不胜感激。提前致谢。

Ser*_*ujo 3

我们使用与其开头匹配的正则表达式捕获每个块,然后将其删除并粘贴到文件的开头。

:$put _ | g/^## 202006[2-3][890]/normal! dapggP
Run Code Online (Sandbox Code Playgroud)

:$put _部分用于在末尾添加一个空行,因此每个块后面都有一个空行。

: .................... vim command mode
$ .................... at end of the file
_ .................... a blank line
|  ................... another vim command
g  ................... a global command
/  ................... start of a search
^  ................... every start of the line
##  .................. two literal ##
202006 ............... literal numbers 
[2-3]  ............... followed by 2 until 3
[890]  ............... followed by 8 9 or zero
/ .................... end of the search
normal! .............. a normal command
dap .................. delete a paragraph
gg ................... jump to the beginning of the file
P .................... put deleted text before the cursor
Run Code Online (Sandbox Code Playgroud)