jJ'*_*jJ' 34
有一个vim特定的正则表达式来做到这一点
:%s/.*\n.*\n.*\n/\0\r/g
Run Code Online (Sandbox Code Playgroud)
编辑:如果你想要一个新行,只需将文本放在\ r \n之前(正确的正则表达式转义,如果它包含一些正则表达式字符)
Eug*_*ash 15
你可以使用宏.完整的过程如下:
qq " start recording to register q (you could use any register from a to z)
o " insert an empty line below cursor
<Esc> " switch to normal mode
jjj " move the cursor 3 lines downward
q " stop recording
Run Code Online (Sandbox Code Playgroud)
然后只需移动到起始行并键入1000@q以执行宏1000次.
" insert a blank line every 3 lines
:%s/\v(.*\n){3}/&\r
: .............. command
% .............. whole file
s .............. replace
/ .............. start pattern that we will replace
\v ............. very magic mode, see :h very-magic
(.*\n) ......... everything including the line break
{3} ............ quantifier
/ .............. start new pattern to replace
& .............. corresponds to the pattern sought in (.*\n)
\r ............. add line break
Run Code Online (Sandbox Code Playgroud)
来源:http://www.rayninfo.co.uk/vimtips.html
我会这样做:
:%s/^/\=(line(".")%4==0?"\n":"")/g
Run Code Online (Sandbox Code Playgroud)
如果您的要求更改为“*每 700 行添加一个新的空行*s”,则此方法有效:) 您只需更改“4”
PS如果我需要这样做,我不会在vim中这样做。sed、awk 可以做得更简单。