Reputation: 543
When I'm using #if 0, #else and #endif preprocessor to comment out my code, vim is showing the syntax properly. But if I use the sequence like this #if 1, #else and #endif vim is supposed to show the code between #else and #endif as commented, but it's not. My vim version is 7.2.411. I'm using these in lot of places in my code and sometimes get confused because no highlight is there. Is there a way to enable this. Thanks for the help.
eg:
#include <stdio.h>
int main()
{
#if 1
printf("inside #if 1\n");
#else
printf("inside #else\n"); // <-- This part should appear in commented syntax
#endif
return 0;
}
Upvotes: 2
Views: 237
Reputation: 5122
Probably you need to upgrade to vim 7.3+, or at least update your syntax file for C. The first few lines of my $VIMRUNTIME/syntax/c.vim (for vim 7.3) are
" Vim syntax file
" Language: C
" Maintainer: Bram Moolenaar <[email protected]>
" Last Change: 2012 May 03
Using the example under :help synID()
, I tried
:echo synIDattr(synID(line("."), col("."), 1), "name")
and get "cCppInElse2". Probably you will get something different.
The usual advice when overriding a default syntax file (or other vim script) is to put it in your own vimfiles directory. I make an exception when the new file is part of a more recent standard distribution: I do want it to be replaced when I upgrade to some future version of vim.
Upvotes: 3
Reputation: 171
If you are using
#if 1
printf("inside #if 1\n"); //This will work always and this is same as if(1){statement;}
#else
printf("inside #else\n"); //This part will never come
Because '#if 1' will always be true.
Upvotes: -2