在 Vi 编辑器中替换多行
这是文件中的一些文本行。我需要使用 vi 编辑器删除某些文本块。
极光(复数:aurora或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.
我有一个像上面这样的输入文件。在此文件中,我必须删除某些出现的文本块,如下所示。
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 开头的行,中间有极光,最后有经度。
This is some lines of text in a file. I need to remove certain block of text using vi editor.
An aurora (plural: auroras or aurorae) is a natural light display in the sky particularly in the high latitude (Arctic and Antarctic) regions, caused by the collision of energetic charged particles with atoms in the high altitude atmosphere (thermosphere).
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.
I have a input file like above. In this file I have to remove certain occurrences of a block of text like the following.
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.
So, I am using following command which is not working :
:g/^Most/,/auroral/,/longitudes./d
I am deleting the lines starting with Most , auroral in the mid and longitudes at the end.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行的操作有明显的限制,但在上下文中,您可以使用:
删除
while
循环,其中while
位于行的开头,直到行首的右大括号。:g/^while/
部分全局搜索以while
开头的行。接下来是对每个匹配行执行的ex
命令。命令为.,/^}/d
,表示从当前行(.
)到以大括号开头的下一行(/^}/
)执行删除操作(d
)。您还可以使用向后搜索或相对运动(?^{?
或.-3
或.+10
)等内容。很难从评论的混乱外观准确说出您的想法(不是您的错 - 评论不保留有用的格式。)
这很简单,我不明白
cool< /code> 对它有任何影响:
这与我原来的答案是同构的。
There are distinct limits on what you can do, but in the context, you could use:
to delete a
while
loop where thewhile
is at the start of a line up to the close brace at the start of a line.The
:g/^while/
part searches globally for lines that start withwhile
. What follows is anex
command that is executed for each matched line. The command is.,/^}/d
, which means from the current line (.
) to the next line starting with close brace (/^}/
) do a delete (d
). You can use things like backward searches or relative motions (?^{?
or.-3
or.+10
) as well.It is difficult to tell from the mangled appearance of the comment exactly what you have in mind (not your fault - comments don't preserve useful formatting.)
That is simple, and I don't see how the
cool
has any effect on it:This is isomorphic with my original answer.
删除块
{ ... }
而不是搜索和替换会更容易。您可以转到该块(内部或括号内的开头)并使用
daB
将其删除It would be easier to delete the block
{ ... }
instead of searching and replacing.You could go to the block (inside or at the openening bracked) and delete it with
daB