Search code examples
searchvimpattern-matchinglines

Search across multiple lines: selection


text example:

<div> test </div>
test test test 
test <div> test
test test test
test </div> test
test test test

I want to select from <div> to </div>.

My search:

<div>\_.\{-}</div>

However..
1) it does not select <div> test </div> on the 1st line.
2) it does select from <div> on the 3rd line but not to the <div> on the 5th line but to the end of the 5th line.

What did I wrong?


Solution

  • in vim try this:

    /<div>\_.\{-}<\/div>
    

    you should escape the last /, so that let vim know that it belongs to the pattern.

    it is /pattern/{offset}<cr> without the escaping, vim thinks the following chars are offsets.

    Update

    It works as you expected here. Using relative simple vim config:

    https://github.com/sk1418/myConf/blob/master/common/base.vimrc

    In the below screenshot, the command line output is from :echo @/ As you see, the highlighted text are exactly what you want.

    enter image description here