MAG
MAG

Reputation: 3075

vim brace matching with comments having brace

I am browsing my cpp code in vim using ctags . At some point I want to go to the starting point of a closing brace i.e. I want to see where this brace starts. So I press % ( via shift + 5 ). Most of the times this works, but sometimes when my code has comments which include a brace it goes to the positions.

For example :

for(int i = 0;i<100;++i)
{ //point 1
  // this is a comment { // point2
  <some 1000 lines  code>

} <== press % here and it goes to point 2

How can i rectify this problem so that it goes to right place i.e. point 1.

Upvotes: 4

Views: 239

Answers (1)

MaKaDev
MaKaDev

Reputation: 21

Use the matchit.vim macro (provided in macros from v6 on):

set nocompatible
filetype plugin on
runtime macros/matchit.vim

Should do the trick...

Upvotes: 2

Related Questions