Vim - 拉入搜索寄存器
有没有简单/快速的方法可以“猛拉”到vim的“最后搜索”寄存器(“/)中?
从vim文档来看,答案似乎是否定的,但它可以通过“let”命令分配:
It is writable with ":let", you can change it to have 'hlsearch' highlight
other matches without actually searching. You can't yank or delete into this
register.
理想情况下我想做的是这样的:
"/5yw
它将拉出光标下的接下来 5 个单词并将它们放入最后一个搜索缓冲区中
或者,如果有一种方法可以搜索指定寄存器的内容,那么这将起作用换句话说,如果我可以这样做:
"A5yw
然后搜索寄存器 A 中的内容,
我能想到的最接近的方法是拉入一个指定的寄存器,然后将该寄存器复制到最后一个搜索寄存器中,例如,
"A5yw
:let @/=@A
冒着让一个很长的问题变得更长的风险,我想说的是,我并不总是想要“yank & 5个单词”。 search”——有时它是 17 个字符,有时它是到行尾,等等......所以硬编码的宏不能给我我想要的灵活性。
Is there any easy/quick way to "yank" into vim's "last search" register ("/)?
From the vim documentation, it appears that the answer is no, but that it can be assigned via a "let" command:
It is writable with ":let", you can change it to have 'hlsearch' highlight
other matches without actually searching. You can't yank or delete into this
register.
Ideally what I'd like to do is something like:
"/5yw
which would yank the next 5 words under the cursor & put them in the last search buffer
Alternatively, if there is a way to search for the contents of a named register, that would work too. In other words, if I could do:
"A5yw
and then search for what is in register A, that would work too.
The closest I can come is to yank into a named register & then copy that register into the last search register, e.g.
"A5yw
:let @/=@A
At the risk of making a long question longer, I want to state that it's not always 5 words I'd like to "yank & search" -- sometimes it's 17 characters, sometimes it's to the end of the line, etc... so a hard-coded macro doesn't give me the flexibility I'd want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
按
/
输入搜索字符串后,您可以使用Ctrl-R
并键入代表您要使用的寄存器的字母。例如。
"Ayw
将单词拉入寄存器 A/^R A
将寄存器 A 的内容放入搜索字符串中。After pressing
/
to enter a search string, you can then useCtrl-R
and then type the letter representing the register that you want to use.eg.
"Ayw
to yank a word into register A/ ^R A
to put the contents of register A into the search string.如果您没有使用任何寄存器来存储拉出的文本,vim 使用
0
寄存器。您可以通过在/
之后输入Ctrl-R 0
来搜索该内容。一个更复杂的例子。假设您想在另一个缓冲区中搜索当前光标下引号内的文本:
yi"
(复制内部引号)/Ctrl-R 0
If you did not use any register to store the yanked text vim uses
0
register. You can search for that by typingCtrl-R 0
after/
.A more complicated example. Say that you want to search in another buffer for the text inside quotes which is under the cursor right now:
yi"
(yank inner quote)/Ctrl-R 0
我正在使用以下代码:
I'm using following code for that:
搜索选择:
如果您想首先拉取一行的一部分,然后使用“v”并移动光标,直到标记了您想要的内容,然后按 y 进行拉取,现在选择位于寄存器 0 中,
然后您可以输入
/Ctrl-R 0
Searching for a selection:
if you want to first yank a section of a line, then use "v" and move with cursors until you have marked what you want, then press y for yank and now the selection is in register 0
you can then type
/Ctrl-R 0
所以基本上是 # 和 * 命令的扩展版本,对吗?听起来您想定义一个自定义运算符(需要动作的命令)。我从来没有真正这样做过,但我确实找到了一个 插件看起来这可能会更容易做到这一点。提供了一些示例。
So basically an extended version of the # and * commands, right? It sounds like you want to define a custom operator (a command that expects a motion). I've never actually done this, but I did find a plugin which looks like it might make it easier to do so. There are some examples provided.