How to make it so my variable names are highlighted?

This page summarizes the projects mentioned and recommended in the original post on /r/vim

Our great sponsors
  • WorkOS - The modern identity platform for B2B SaaS
  • InfluxDB - Power Real-Time Data Analytics at Scale
  • SaaSHub - Software Alternatives and Reviews
  • nvim-treesitter

    Nvim Treesitter configurations and abstraction layer

  • Vim's regex-based syntax highlighting cannot detect variables in C code. If you don't mind switching to Neovim, you can use nvim-treesitter to use tree-sitter queries to highlight C files (a default set of queries is available out of the box, which do highlight variables) instead.

  • vim-lsp-cxx-highlight

    Vim plugin for C/C++/ObjC semantic highlighting using cquery, ccls, or clangd

  • By looking around the Web, I think you can maybe do what you want in Vim with this plugin, which requires you to setup an LSP server for C (note: I haven't tried it). Otherwise, the way Vim makes its syntax highlighting (natively) simply cannot compete with tree-sitter or LSP-based highlighting which construct the entire AST of your code, because C's syntax is too complex. There is a proposal to include an alternative syntax highlighting system, but work on it hasn't even started as far as I know, so vim-lsp-cxx-highlight and tree-sitter are really the only way to highlight identifiers in C/C++.

  • WorkOS

    The modern identity platform for B2B SaaS. The APIs are flexible and easy-to-use, supporting authentication, user identity, and complex enterprise features like SSO and SCIM provisioning.

    WorkOS logo
  • Vim

    The official Vim repository

  • By looking around the Web, I think you can maybe do what you want in Vim with this plugin, which requires you to setup an LSP server for C (note: I haven't tried it). Otherwise, the way Vim makes its syntax highlighting (natively) simply cannot compete with tree-sitter or LSP-based highlighting which construct the entire AST of your code, because C's syntax is too complex. There is a proposal to include an alternative syntax highlighting system, but work on it hasn't even started as far as I know, so vim-lsp-cxx-highlight and tree-sitter are really the only way to highlight identifiers in C/C++.

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts