Reputation:
Is there a way to have % in vim find the next ([{ or whatever, even if it is not on the same line?
Example:
int main(int argc, char ** argv) {
#Your cursor is somewhere in this comment, I want
#it to get to the ( after printf
printf("Hello there.\n");
}
Upvotes: 2
Views: 441
Reputation: 4547
If you want to find opening braces on subsequent lines, without plugins, just enter normal mode and type:
/{ [enter]
Where { is the type of brace your looking for.
You can then browse them all with n and N.
To map the F12 key to turn search highlighting on and off use this trick.
Upvotes: 4
It looks like Jim Burger has it, but just in case you were actually asking how to search for any of those things:
/[{[(] [Enter]
This will find the next of any of those symbols.
By the way: In this case, vim is smart enough to figure out what you want, but you'll often have to escape a square or round bracket with '\'. For example, to search for the next closing bracket, you would type (Note the \]):
/[\]})] [Enter]
Upvotes: 1
Reputation: 10824
If I understand correctly, you're trying to to get it to find the opening brace even on the next line. If you're complaining that it doesn't find the closing brace unless the whole thing is one line, I don't know why that wouldn't be working.
In any case, if you want % to have superpowers, the matchit plugin is the place to start. It's included in the normal distribution, so you shouldn't have to download it. Just add
:runtime macros/matchit.vim
To your .vimrc, and % will also know lots of new tricks (how to match balaced XML tags if/then/end if statements in languages that do those with keywords), etc. It won't solve your request directly, since matchit uses the same limitations as normal % (it wasnts the match to start at or after the cursor, on the same line). But since it can use regex searches as match markers (instead of just characters), it should be possible to configure it so the open expression is .\n.{ or some such that would meet that criteria, yet pick up a brace on a line further down.
Upvotes: 2
Reputation: 1690
That's puzzling... For me, % finds the matching close for any {[( no matter how many lines away the match is. I don't see anything in my .vimrc that would change this behaviour, offhand.
Upvotes: 1