Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to move to the next enclosing brackets in VI

Tags:

c++

vim

vi

Are there any shortcuts to move to the next enclosing brackets. For ex:

int func()
{

 if(true)
 {//this point

   for(int i=0;i<10;i++)
   {//need to jump from here to

    //blah blah blah

   }

 }
}

I can move to the beginning of a function using [[ but not sure how to move to the next enclosing brackets. Thanks for any info...

like image 556
VNarasimhaM Avatar asked Oct 02 '09 14:10

VNarasimhaM


People also ask

How do you jump to the next bracket in Vim?

The % key. You can use the % key to jump to a matching opening or closing parenthesis, square bracket or a curly brace.

How do I match brackets in vi?

You simply put your cursor on a brace or parenthesis, press %, and Vi will move the cursor to the corresponding brace or parenthesis.


2 Answers

Can't think of anything easier than /{

[{ will go to an unmatched one, but that isn't what you want.

like image 69
Jeff Walker Avatar answered Sep 26 '22 06:09

Jeff Walker


Put the cursor on one bracket and hit the percent key.

Also setting the 'showmatch' option makes the cursor jump to the matching opening bracket when you type the closing bracket.

Adding a declaration like this:

set matchpairs+=<:>

Will add angle brackets to the standard list of match pair brackets.

like image 25
Rob Wells Avatar answered Sep 25 '22 06:09

Rob Wells