在 VIM 中重用 ex 命令中的先前范围 [英] Reusing the previous range in ex commands in VIM

查看:21
本文介绍了在 VIM 中重用 ex 命令中的先前范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 VIM 中重用 ex 命令的范围?

Is it possible to reuse the range of ex commands in VIM?

例如,我可以使用以下命令将当前文件中的第 4 行到第 10 行写入(复制)到一个新文件中:

As an example, I can write (copy) lines 4 to 10 from my current file to a new file using the following command:

:4,10w foo/bar.txt

但我真正想做的是将这些行移动到一个新文件中.我可以这样做:

But what I really want to do is move the lines to a new file. I can do this like so:

:4,10w foo/bar.txt
:4,10d

但是每次都必须输入 4,10 有点烦人.

But it's a bit annoying to have to type 4,10 both times.

所以我有两个问题:

  1. 一般,有没有办法在 ex 命令中引用以前使用的范围?
  2. 具体来说,如果没有办法执行 (1),是否有任何更简单的方法可以将一个文件中的多行剪切并粘贴到一个新文件中.
  1. Generally, Is there a way to reference the previously used range in ex commands?
  2. Specifically, if there is not a way to do (1), is there any easier way to cut and paste a number of lines from one file into a new one.

推荐答案

我通常使用 cat 来做这个:

I usually use cat to do this:

:4,10!cat > foo/bar.txt

这是有效的,因为您通过 cat 管道线并用结果输出替换它们,这没什么.当然,您可以通过执行 >> 而不是 > 来附加到现有文件的末尾.

This works because you're piping the lines through cat and replacing them with the resulting output, which is nothing. And of course you can append to the end of an existing file by doing >> instead of >.

这篇关于在 VIM 中重用 ex 命令中的先前范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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