How to search for a string containing the letter "foo" above a string

In vim, you can find a string containing the letter "foo" above the string.

Example file fragment:

class A {
    int a;
}  

class B {
     int a;
}

     // something else with 5 spaces

In this example, I want to be able to search for class B since it followed exactly 5 spaces in the next line, but not my search to find Class Aor comment with 5 spaces.

+3
source share
1 answer

Your question is not very clear, but maybe this search will work for you in vim:

/^\s*class.*\n^\s\{5}

This will search for the keyword in one line, followed by the exact 5 spaces in the next line.

+3
source

All Articles