:% s/\v^(.{4})(.*)$/\1/g
这个以保留每一行的前四个字符为例,主要参考内容为:https://vi.stackexchange.com/questions/7562/how-to-copy-first-four-characters-of-every-line-to-the-end-of-that-same-line
\v
magic option, to avoid having to escape grouping()
^
start of line- $ end of line
\d{4}
match exactly four digits.*
rest of line\1
has the matched pattern within()
vim 去除重复行
:sort
:g/^\(.*\)$\n\1$/d
vim 删除匹配的行和一定范围内的行
- 对于当前和下一行:
:g/match/.,+1d
- 对于当前行和上一行:
:g/match/-1,.d
- 对于上一行,当前行和下一行:
:g/match/-1,+1d