In Source Insight, global variable show up in a different colour. Is there a way to accomplish this in vi (or any other free editor)?

  • 1
    That kind of question would be better suited to StackOverflow or SuperUser because it is a quite specific question about a software tool, not a general questions about "programmers". – Xavier T. Jan 13 '11 at 10:08
  • Have you heard about vi.stackexchange.com ? – Mael Nov 14 '16 at 12:51
  • @Mael This question is from Jan 2011. I'm not sure if vi.se existed back then. I looked at web.archive.org/web*/vi.stackexchange.com and the first cached page is from Feb 2015. – hojusaram Nov 15 '16 at 7:13
  • Good point. I didn't notice the date the question was asked. – Mael Nov 15 '16 at 9:41

It may not be quite what you want, but you could have a look at my TagHighlight plugin for Vim.

Assuming your chosen language is supported by it (or at least by ctags: it's quite easy to add new languages), this plugin will use ctags to parse your source tree and identify a lot of extra keyword types (including global variables, which will be highlighted in the GlobalVariable style, so you'll need to define this if your colour scheme doesn't do so already).


To do this the editor would need to be context aware (ie understand the syntax of the language) this requires the editor to be integrated with the compiler.

So though vim can do syntax highlighting of a very complex nature. This type of functionality is beyond it (well knowing how vim can be hacked I am sure somebody will now come and show how it is done, but it will not be trivial).

Vim's syntax highlighting falls into three categories:

  • Keywords
  • Matches (basically regular expressions)
  • Regions (A start regular expression and end regular expression)

About the only editor that is probably capable of this (and I am not sure it is). Is the one built into "Visual Studio 2010" (Though some emacs guru is going to come and say otherwise).

  • I know that vim by itself would not be able to do this. You could do this with some kind of static analysis tool (similar to cscope or ctags but they would have to understand the scope of the variables). I was wondering if such a tool exists. – hojusaram Jan 12 '11 at 18:26
  • 1
    @hojusaram: You could use a convention (So that it is easy to write a regular expression for). Example: Prefix all global variables with g_. Then vim would easily pick thus up and highlight them appropriately. – Martin York Jan 12 '11 at 18:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.