Comments (9)
I am not completely against it, but with Vim's currently shipped c.vim syntax file it just won't work most of the time.
What you asked for could be accomplished with something like:
syntax match cppSTLscoped "::" nextgroup=cppSTLtype
syntax keyword cppSTLtype contained hours path vector
highlight default link cppSTLtype Type
Now when hours
, path
or vector
appear after a ::
they will be highlighted as Type
. The contained
(alternatively we could also write containedin=cppSTLscoped
) makes sure that these keywords are highlighted only when contained in another syntax group and not on their own.
But the problem is the ALLBUT
option in the following syntax declaration in Vim's default c.vim
syntax file:
https://github.com/vim/vim/blob/67fbdfefd26a237831c3838f799d3e6198c8a34a/runtime/syntax/c.vim#L161-L162
It basically says that any syntax group contained inside parentheses will be highlighted. See :help syn-contains
for more details. This means, cppSTLtype
will be highlighted when appearing inside parentheses, even without the preceding ::
. For example, path
will be highlighted in both foo(path)
and foo(std::path)
.
A workaround is to clear the already declared syntax group cParen
and redefine it with cppSTLtype
:
syntax clear cParen
syntax region cParen transparent start='(' end=')'
\ contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,@cStringGroup,@Spell,cppSTLtype
Now cppSTLtype
is highlighted only when appearing after a ::
.
When you look at the shipped c.vim syntax file, cParen
is declared multiple times, depending on the file type, the C++ standard, and whether or not the user wants curly or bracket errors highlighted. I am very hesitant to copy/paste all those lines just for the sake of cppSTLtype
. And I haven't found another way yet.
There is already a request to fix this ALLBUT
behavior, see vim/vim#1265.
from vim-cpp-modern.
Something like
syntax region cppSTLscoped start='\(std\)\@3<=::\<' end='\>' contains=cppSTLtype
syntax keyword cppSTLtype allocator contained
syntax keyword cppSTLtype auto_ptr contained
syntax keyword cppSTLtype basic_filebuf contained
...
(with separate groups for each namespace if we want to actually check the namespace, or with a single container group just checking for a preceding ::
) works.
from vim-cpp-modern.
@anntzer I gave up on such complicated syntax highlighting long time ago. I didn't really need it anyway. Have you tried color_coded?
from vim-cpp-modern.
The main problem I have with color_coded (and other similar tools) is the need to maintain a .color_coded
file. My use case is often python extension modules, where the build flags are generated by setup.py and often requires shelling out to pkg-config anyways. In fact the include paths are likely to be different from one environment to another, so a static .color_coded
will just not be enough.
from vim-cpp-modern.
There's YCM-Generator that also generates .color_coded
files.
from vim-cpp-modern.
It does not support setuptools (https://github.com/rdnetto/YCM-Generator#requirements-and-limitations). Even if I were to write it manually, .color_coded is necessarily a static list of flags, which is not sufficient (pkg-config actually returns different paths on different build systems for me).
If .color_coded was actually able to interpolate subcommands (or run some $scriptlanguage) then I would be able to manually work around it, but right now it's not the case.
from vim-cpp-modern.
Have you looked at the alternatives clighter8 or chromatica.nvim? Both are written in python.
There is also taghighlight, which highlights keywords based on a ctags file.
from vim-cpp-modern.
From a quick look, all the compiler-based projects suffer from the same issue (already mentioned above): they require a static list of compile flags (which may or may not be autogenerated via cmake/bear/etc.). This does not handle the (my) case where your compilation options are e.g. $(CXX) $(pkg-config --cflags pkg) ...
: good old makefiles are not dead yet.
TagHighlight may or may not work, haven't looked too much into it.
from vim-cpp-modern.
I also find it annoying to have variables like "hours", and "path" highlighted like they were special.
Maybe a simpler solution would be an option to not highlight these unless there is a leading "::".
from vim-cpp-modern.
Related Issues (20)
- can we have highlight on "#define" and "using vec = vector<int>" that self define type HOT 3
- concept is not highlighted HOT 6
- About the displayed colorscheme HOT 2
- Hightlighting custom types that have the `_t` postfix HOT 3
- concept/requires highlight HOT 2
- std::ref and std::cref HOT 5
- How can I mark variable with specific beginnings as member variable? HOT 1
- Brace construction in lambdas is highlighting as an error HOT 2
- the highlight doesn't change after installing HOT 12
- The highlight doesn't work on mac with files named with "*.C" and ".H" HOT 3
- Template function not highlighted HOT 1
- how to make cpp_no_cpp20 work HOT 1
- Add highlighting for C++20 `concept` and `requires` keywords HOT 1
- no highlight for from_chars HOT 2
- i think most of us agree user defined type starts with capital letter HOT 1
- adding modules related keywords HOT 2
- What needs to be added to .vimrc to make this work? HOT 8
- Missing highlight of C++23 integer literals HOT 2
- let g:cpp_no_function_highlight=1 option missing / not working HOT 2
- Incorrect function highlighting HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim-cpp-modern.