识别相同的代码块 [英] Identifying Identical Blocks of Code

查看:183
本文介绍了识别相同的代码块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我在一个文件中有多个以下代码块(空格是不重合的):

  sdgfsdg dfg 
dfgdfgf ddfg
dfgdfgdfg dfgfdg

您如何查找/突出显示所有出现的内容?



理想情况下,我想要做的就是直观地选择代码块,然后按搜索查找所有匹配项。

解决方案

正在搜索的文本存储在 / 寄存器中。你不能直接插入或删除这个寄存器,但你可以使用`let'来分配它。



试试这个:


  • 使用可视化模式突出显示要搜索的代码 c>将选中的内容突出显示为 a

  • 输入:let @ / = @a 将寄存器 a 复制到搜索寄存器 /

  • ul>

    此时,与您的选择相匹配的所有代码都将突出显示,并且您可以像使用常规搜索一样使用n / N浏览出现次数。



    当然,您可以使用任何临时寄存器而不是 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 register a
    • Type :let @/ = @a to copy register a 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屋!

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