复制变量列表的VIM方法是什么(垂直与不同宽度对齐的单词列表)?
let(:aaaaa) { 123 }
let(:bb) { true }
let(:ccc_ccc) { "foo bar" }
我想复制所有变量名称(:aaaaa,:bb,:ccc_ccc)。
例如,在VScode中,我将使用多行选择。
我该如何在VIM中进行?
一旦变量名称具有不同的长度,则块选择无效。
let(:aaaaa) { 123 }
let(:bb) { true }
let(:ccc_ccc) { "foo bar" }
I want to copy all variable names (:aaaaa, :bb, :ccc_ccc).
In VsCode, for example, I would use a multi-line selection.
How can I do it in VIM?
Block selection didn't work, once the variable names have a different length.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用命令
:%norm f:“ qyt)
使您的'q寄存器'包含如下:
它的工作方式如下:
:%norm
对所有行,应用以下命令'f:
将光标移动到该上的第一个冒号行“ qy
将猛拉的文本附加到'q'寄存器t)
是一个动作',直到下一个关闭括号为止,假设'q'寄存器已经空了(您可以使用
QQQ
清除它)。如果您只想在一部分行中执行此操作,则需要替换
%
具有范围(或视觉选择)。
在此之后,您对寄存器的内容做了什么。
“ QP
将它们放入缓冲区中,也许您会做:s/:/:/\ r:/g
to to to这样的结肠分开线:
You could use the command
:%norm f:"Qyt)
to make your 'q register' contain thefollowing:
The way it works is as follows:
:%norm
means 'to all lines, apply the following normal commands'f:
moves the cursor to the first colon on the line"Qy
appends yanked text to the 'q' registert)
is a motion 'till the next closing parenthesisThis assumes that the 'q' register is already empty (you can use
qqq
to clearit). If you only want to do this for a subset of lines, you'd replace the
%
with a range (or visual selection).
What you do with the register's contents after that is up to you.
"qp
will put them into the buffer, and maybe you'd then do:s/:/\r:/g
tosplit the lines at the colons like this:
如果您的近期目标是在默认寄存器中拥有类似的目标:
如果没有视觉上选择多个不连续的文本的任意长度的文本,那么实现这一目标并不容易盒子。
这意味着,如果我们不想使用多个光标插件,那么我们将留下更多涉及替代,宏等的行人方式。
如果光标在第一行,您可以做类似的事情:
但是VIM效果最好。当它意图使用时。 “复制此”很少是一个目标:它通常是完成高级任务所需的几个低级步骤之一(这本身可能是另一个甚至更高级别的任务的步骤之一)。一个人打算与复制文本有关的事情通常在选择最佳策略方面起着重要的作用。在这里,您的实际目标可能是将三个变量名称在其定义下方的三行上获取,这实际上并不意味着复制它们,因此两个第一步就足够了。
If your immediate goal is to have something like this in the default register:
then it won't be easy to achieve without the ability to visually select multiple non-contiguous pieces of text of arbitrary length, which Vim doesn't have out of the box.
This means that, if we don't want to use a multiple cursors plugin, we are left with more pedestrian ways involving substitutions, macros, etc.
Assuming the cursor is on the first line, you could do something like:
But Vim works best when it is used with intent. "Copy this" is rarely a goal in and of itself: it generally is one of the several low-level steps necessary to complete a higher-level task (which itself might be one of the steps of another even higher-level task). What one intends to do with the copied text often plays an important role in choosing the best strategy. Here, your actual goal may have been to get the three variable names on three lines right below their definition, something that actually doesn't imply copying them, so the two first steps would have been enough.