删除 Vim 中的行并将其重定向到另一个文件 [英] Delete and redirect lines in Vim to another file

查看:33
本文介绍了删除 Vim 中的行并将其重定向到另一个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想删除最后 10 行并将其移动到另一个文件中.

I want to delete say last 10 lines and move it to another file.

我目前做的是:

  • 在可视模式下选择最后 10 行,
  • 将这些行由 :'<,'>w 写入其他文件,
  • 然后删除选定的行.

有没有更有效的方法可以做到这一点?

Is there any more efficient way I can do this?

推荐答案

您可以通过执行以下操作删除一步:

You can remove one step by doing this:

  • 目视选择线条
  • <代码>:!>newfile.txt

这将使用外部命令将行写入给定的文件名,同时删除它们,因为该命令没有输出任何内容.

This will use an external command to write the lines to the given filename, and simultaneously delete them because nothing was output from the command.

如果您想附加到文件而不是覆盖它,请使用 >> 而不是 >.

If you want to append to a file instead of overwriting it, then use >> instead of >.

这篇关于删除 Vim 中的行并将其重定向到另一个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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