如何选择不在连续块中的多行?

发布于 2024-12-02 14:16:55 字数 1016 浏览 2 评论 0原文

我正在尝试选择不在连续块中的多行。例如,我想同时选择第 1 行和第 3 行,而不选择第 2 行:

 1. this is line 1 
 2. this is line 2 
 3. this is line 3

最初我认为这将是一个琐碎的任务,但在花了相当长的时间谷歌搜索无济于事后,我意识到这可能不是一个简单/常见的任务。

非常感谢您的帮助。


编辑: 感谢您的回复。我将提供更多关于我如何提出这个问题的细节。

我试图使用 Tabularize 来对齐如下的块代码:

1. name1="Woof"
2. lucky_dog = lucky( "dog_one"= name1, 
3.                    "dog_two"= name1 )
4. name2="Howl"

我希望它像这样对齐:

1. name1     = "Woof"
2. lucky_dog = lucky( "dog_one"= name1, 
3.                    "dog_two"= name1 )
4. name2     = "Howl"

但我不能这样做,因为 Tabularize 会考虑第三行,并将所有内容对齐到:

1.name1                        = "Woof"
2.lucky_dog                    = lucky( "dog_one"= name1,
3.                   "dog_two" = name1 )
4.name2                        = "Howl"

我相信我可以想到一些正则表达式归档所需结果的技巧,一开始我只是想到也许我可以简单地选择第 1,2,4 行并使它们对齐。

然后我意识到这不是一件容易的事。

因此就有了这个问题。

感谢您的回复!

I am trying to select multiple lines that are not in a continuous chunk. E.g., I want to select line 1 and 3 simultaneously without selecting line 2:

 1. this is line 1 
 2. this is line 2 
 3. this is line 3

Initially I thought this would be a trivia task, but after spending quite some time googling around to no avail, I realized this might not be a simple/common task.

Many thanks in advance for your help.


Edit:
Thanks for the responses. I will provide a little more details on how I came up with the question.

I was trying to align a chunk code like the following, using Tabularize:

1. name1="Woof"
2. lucky_dog = lucky( "dog_one"= name1, 
3.                    "dog_two"= name1 )
4. name2="Howl"

I wanted it to align like this:

1. name1     = "Woof"
2. lucky_dog = lucky( "dog_one"= name1, 
3.                    "dog_two"= name1 )
4. name2     = "Howl"

But I cannot do so because Tabularize will take third line into consideration, and align everything into:

1.name1                        = "Woof"
2.lucky_dog                    = lucky( "dog_one"= name1,
3.                   "dog_two" = name1 )
4.name2                        = "Howl"

I believe I could think of some regex trick to archive the desired results, it just occurred to me at first that maybe I could simply select line 1,2,4 and make those align.

Then I realized this is not a easy task.

Hence the question.

Thanks for the responses!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

邮友 2024-12-09 14:16:55

现在有一个出色的插件可以在 Vim 中实现多选: Vim-multiple-cursors:

在此处输入图像描述

There is now a brilliant plug-in that enables multi-select in Vim: Vim-multiple-cursors:

enter image description here

迷离° 2024-12-09 14:16:55

在 vim 中不可能选择不同的文本块。

相反,您可以做的是识别您想要操作的行共享的常见、唯一模式,并使用“全局”ex 命令或“g”来执行此操作,如下所示:

:g/shared unique pattern/ex or normal command here

例如,将行复制到寄存器,说'a'寄存器:

:g/shared unique pattern/normal "Ayy

要粘贴它们,请点击“ap

yy之前的大写字母A告诉vim你想复制这些行并将其附加到a寄存器。

就像sydill所说,如果你能告诉我们你到底想要什么那么与线条有关我们可以更好地帮助您。

It's not possible to select different chunks of text in vim.

What you can do instead is identify a common, unique pattern that is shared by the lines you want to act on and use the 'global' ex-command or 'g' to do it like so:

:g/shared unique pattern/ex or normal command here

For example to copy the lines to a register, say the 'a' register:

:g/shared unique pattern/normal "Ayy

To paste them hit "ap

The capital A that comes before yy tells vim that you want to copy and append the lines to the a register.

Like sydill said if you can tell us what exactly you want to do with the lines then we can better help you.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文