在减价中排序/反转部分(使用VIM)

jrcvhitl  于 2022-11-11  发布在  其他
关注(0)|答案(1)|浏览(144)

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


## 20200628

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

## 20200629

- Homepage rebuilding

## 20200630

- 13:00: Meeting Tom

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


## 20200630

- 13:00: Meeting Tom

## 20200629

- Homepage rebuilding

## 20200628

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

我希望使用VIM,但我不知道什么是一个适当的方式来实现这一点。任何建议将不胜感激。提前感谢。

xe55xuns

xe55xuns1#

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

:$put _ | g/^## 202006[2-3][890]/normal! dapggP

:$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

相关问题