Search code examples
searchvim

How do I search within a selected block of code with vim


say, I want to search for a particular text withing a function block. The present way, that i am implementing is selecting the block of code from within the function brackets with vi{ and then copying it and pasting it to a new file. After that I am searching for the text within the new file with /<search-text>

I want to know, if there is a short cut to this?


Solution

  • vi{
    :'<,'>g/foo/#
    

    The '<,'> range is inserted automatically.

    See :help range and :help :g.