如何删除 Vim 中的所有其他行? [英] How to delete every other line in Vim?

查看:35
本文介绍了如何删除 Vim 中的所有其他行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从 Vim 缓冲区中每隔一行删除一行,从第二行开始,即第 2、4、6 行等.例如,如果缓冲区的内容是:

I would like to delete every other line from a Vim buffer, starting with the second one, i.e., lines 2, 4, 6, etc. For example, if the buffer’s contents is:

aaa
bbb
ccc
ddd
eee
fff

然后,在删除所需的行后,它应该变成:

then, after the desired line removal, it should become:

aaa
ccc
eee

哪些 Vim 命令可用于自动执行此操作?

Which Vim commands can be used to automate this operation?

推荐答案

您可以为此使用宏.执行以下操作.

You can use a macro for this. Do the following.

  • 在命令模式下启动.
  • gg 转到文件的开头.
  • qq.
  • 单击向下箭头,然后按 dd.
  • q.
  • 10000@q
  • Start in command mode.
  • Go to the beginning of the file by pressing gg.
  • Press qq.
  • Click arrow down and press dd after.
  • Press q.
  • Press 10000@q

PS:要进入命令模式,只需按几次 Escape.

PS: To go to command mode just press Escape a couple of times.

这篇关于如何删除 Vim 中的所有其他行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆