这是文件中的几行文本。我需要使用 vi 编辑器删除某些文本 block 。
极光(复数:auroras 或 aurorae)是天空中的自然光显示,特别是在高纬度(北极和南极)地区,由高能带电粒子与高海拔大气(热层)中的原子碰撞引起.
Most aurorae occur in a band known as the auroral zone[2][2] which is typically 3° to 6° in latitudinal extent and at all local times or longitudes.
The auroral zone is typically 10° to 20° from the magnetic pole defined by the axis of the Earth's magnetic dipole. During a geomagnetic storm, the auroral zone will expand to lower latitudes. The diffuse aurora is a featureless glow in the sky which may not be visible to the naked eye even on a dark night and defines the extent of the auroral zone.
我有一个像上面这样的输入文件。在此文件中,我必须删除某些出现的文本 block ,如下所示。
Most aurorae occur in a band known as the auroral zone[2][2] which is typically 3° to 6° in latitudinal extent and at all local times or longitudes.
所以,我正在使用以下不起作用的命令:
:g/^Most/,/auroral/,/longitudes./d
我正在删除以 Most 开头的行,中间是 auroral,末尾是 longitudes。
最佳答案
你可以做什么有明显的限制,但在上下文中,你可以使用:
:g/^while/.,/^}/d
删除 while
循环,其中 while
位于一行的开头,直到一行开头的右大括号。
Can you please add some more to this?
:g/^while/
部分全局搜索以 while
开头的行。接下来是为每个匹配行执行的 ex
命令。命令为.,/^}/d
,表示从当前行(.
)开始到下一行以右大括号(/^}/
) 执行删除 (d
)。您也可以使用向后搜索或相对运动(?^{?
或 .-3
或 .+10
)之类的东西。
很难从评论的困惑外观中准确判断出您的想法(这不是您的错 - 评论不会保留有用的格式。)
--------------
Stack Over Flow
c**p
c**p
c**p
cool
c**p
c**p
c**p
------------
I need to replace from Stack Over Flow to
------------
[...]
这很简单,我看不出 cool
对它有什么影响:
:g/^Stack Over Flow/.,/^-------/d
这与我原来的答案同构。
关于regex - 在 Vi 编辑器中替换多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7857491/