5

I have large amount of C code and a large portion of the code is commented out and/or #if 0. When I use the % key to match the open and close brackets of if-else, it matches the commented out code too.
Is there a way or a vim plugin that would not consider the commented out or #if 0 code, while matching brackets.

Currently I am using snipMate and omniComplete vim plugins.

Harman
  • 1,571
  • 1
  • 19
  • 31

2 Answers2

3

As mentioned by david, the matchit plugin is able to skip over comments. However, the syntax group that the C syntax script defines for #if 0 is not configured in the plugin. Create a file ~/.vim/after/ftplugin/c.vim and put the following into it:

" Make the matchit plugin also skip over sections commented out via #if 0.
let b:match_skip .= '\|cCppOut2'
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
1

The matchit plugin (included with vim but not enabled) should do this by default for commented out code. Pretty sure it won't work with #if 0 code. Check out :h matchit and :h match_skip

david
  • 5,919
  • 1
  • 17
  • 7