Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim brace matching with comments having brace

Tags:

c++

vim

vi

ctags

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.

like image 765
MAG Avatar asked Oct 23 '25 18:10

MAG


1 Answers

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

set nocompatible
filetype plugin on
runtime macros/matchit.vim

Should do the trick...

like image 72
MaKaDev Avatar answered Oct 26 '25 09:10

MaKaDev