octol / vim-cpp-enhanced-highlight

Additional Vim syntax highlighting for C++ (including C++11/14/17)
MIT License
1.06k stars 152 forks source link

Variable name highlighted wrong #54

Closed andreyorst closed 5 years ago

andreyorst commented 6 years ago

Hello. This is not critical issue, but sometimes variables are colored as functions. I don't see it often, but seems like it represents when variable name is same as some function, beg for example. It happens with other names too. For example:

template<typename T>
void mysort(T beg, T end) {
    sort(beg, end);
}

will be colored in vim like: image beg is the same blue as sort, which is confusing when you do a quick lookup on the code. All other variables are always colored white.

I've checked it in other programs and I found that it is a common problem.

Sublime Text: image ...

KDevelop: image interesting...

Visual Studio Code: image well, it's just stupid

in Code::Blocks it works slightly different from vim: image

octol commented 6 years ago

Indeed quite interesting that it happens in other editors/IDEs too.

andreyorst commented 6 years ago

what I've found: If you call a variable, for example main, it will be colored as a function. So i think that the highlighting system knows all of the standard names, not only for types and constructions like template, but a common functions too. But user-defined functions are colored only if they have a parentheses () after it. Screenshot to assume everything: image

The code (to try in other editors, if wanted):

void fo() {
    char maen;
    maen = 'a';
}

void foo
() {
    char main;
    main = 'a';
    int template;
    template = 5;
    bool vector;
    vector = true;
} 

int main
() {
    fo
    ();
    foo();
}

Don't think that I use such style in my daily programming

void foo
() {
    // ...
}

It's just to show what I mean.