Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move to next open or closing parenthesis in VIM

Tags:

vim

editor

I'm looking for a way to move to the next open or closing bracket of a certain type, e.g. { or }. Example:

if(true)
{
   for(int i = 0; i < 10; i++)
   {
       SomeFunction();
       SomeOtherFuntion();
   }
}

Let's say my cursor is on the 'S' in SomeFunction() and I want to jump to the next }, i.e. the end bracket of the for loop.

What is an efficient way to do this? The only way I can think of is using /}[ENTER], but I'm wondering if there's a simpler way.

like image 833
seg Avatar asked Nov 01 '12 10:11

seg


1 Answers

Have a look at :help motion.txt, it contains all the various alternatives.

For { in the first column, there's ]]. For unmatched ones, ]}. In many languages, { represents the start of a method, then ]m can be used. But in general, I see no problem with your suggestion of /}<CR>. If you use that often, you can always define a custom mapping for it:

:noremap ]] /}<CR>
like image 54
Ingo Karkat Avatar answered Oct 09 '22 21:10

Ingo Karkat