Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to restrict the % functionality of vim?

Tags:

vim

vim-plugin

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.

like image 510
Harman Avatar asked Oct 07 '22 00:10

Harman


2 Answers

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'
like image 198
Ingo Karkat Avatar answered Oct 10 '22 03:10

Ingo Karkat


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

like image 28
david Avatar answered Oct 10 '22 03:10

david