识别相同的代码块 [英] Identifying Identical Blocks of Code
问题描述
sdgfsdg dfg
dfgdfgf ddfg
dfgdfgdfg dfgfdg
您如何查找/突出显示所有出现的内容?
理想情况下,我想要做的就是直观地选择代码块,然后按搜索查找所有匹配项。
正在搜索的文本存储在 /
寄存器中。你不能直接插入或删除这个寄存器,但你可以使用`let'来分配它。
试试这个: 此时,与您的选择相匹配的所有代码都将突出显示,并且您可以像使用常规搜索一样使用n / N浏览出现次数。 当然,您可以使用任何临时寄存器而不是
a
:let @ / = @a
将寄存器
a
复制到搜索寄存器 /
ul>
a
。并且,映射此命令序列不应太困难容易使用。
Say I have multiple blocks of the following code in a file (spaces is irrelavent):
sdgfsdg dfg
dfgdfgf ddfg
dfgdfgdfg dfgfdg
How do you find/highlight all the occurrences?
What I ideally want to do is to visually select the code block and then press search to find all occurrences.
The text being searched for is stored in the /
register. You can't yank or delete directly into this register, but you can assign to it using `let'.
Try this:
- Use visual mode to highlight the code you want to search for
- Type
"ay
to yank that highlighted selection into registera
- Type
:let @/ = @a
to copy registera
into the search register/
At this point, all code matching your selection will be highlighted, and you can navigate through occurrences using n/N just as you would a regular search.
Of course, you can use any temporary register instead of a
. And it shouldn't be too difficult to get this command sequence mapped for easy use.
这篇关于识别相同的代码块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!