Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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)?

share|improve this question
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

2 Answers 2

up vote 2 down vote accepted

It may not be quite what you want, but you could have a look at my CTagsHighlighting 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).

share|improve this answer
    
Thank you! This is exactly what I was looking for. –  hojusaram Jan 24 '11 at 20:35

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).

share|improve this answer
    
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. –  Loki Astari Jan 12 '11 at 18:32

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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