LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-02-2003, 02:20 AM   #1
new_user10
Member
 
Registered: Jun 2003
Posts: 30

Rep: Reputation: 15
vim color highlighting


hello everyone,

when programming in c with emacs, after a variable is declared, i have seen emacs highlight the variable name throughout the rest of the code.

can vim do the same thing. currently with syntax highlighting, vim highlights keywords in c (for, while, if, etc.) and types (int, float, etc.), but it does not highlight user-defined types (struct names, etc.) or variable names.

does anyone know the appropriate commands/plugins to make these highlight? thanks.

-tko
 
Old 11-02-2003, 02:24 AM   #2
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
not on a brand spanking new file. but if you save it right after opening (like hello.cpp), it will syntax highlight. if you use gvim (vim-x11) there's a menu item where you can choose the language and it will syntax highlight based on the language you choose.
 
Old 11-02-2003, 02:33 AM   #3
new_user10
Member
 
Registered: Jun 2003
Posts: 30

Original Poster
Rep: Reputation: 15
thanks megaspaz, but...

the syntax highilighting works. i am just wondering how one would highlight user-defined elements such as variable names and struct names.

also, i have access to only vim and not gvim, because i am using a terminal and cannot run any x sessions.

any ideas?
 
Old 11-02-2003, 02:38 AM   #4
megaspaz
Senior Member
 
Registered: Nov 2002
Location: Silly Con Valley
Distribution: Red Hat 7.3, Red Hat 9.0
Posts: 2,054

Rep: Reputation: 46
Quote:
Originally posted by new_user10
thanks megaspaz, but...

the syntax highilighting works. i am just wondering how one would highlight user-defined elements such as variable names and struct names.

also, i have access to only vim and not gvim, because i am using a terminal and cannot run any x sessions.

any ideas?
as far as user defined variables and such, i don't know. for me it's plain white text also. never thought about it though. sorry.
 
Old 11-02-2003, 06:34 AM   #5
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I looked it up, and as far as I could find out, having a file ~/.vim/colors/myColors.vim with the line below should do it, but it doesn't seem to work on my vim :-(
Changing colors in this file for i.e. "Comment" does work. Strange. If somebody knows how to make it work I would also be interested. Using vim 6.1 from debian sarge/testing package.
Code:
hi Identifier   ctermfg=darkgreen cterm=none guifg=palegreen
 
Old 11-02-2003, 06:43 AM   #6
paonethestar
Member
 
Registered: Oct 2003
Posts: 47

Rep: Reputation: 16
In what sense u are asking ?? .I mean if u are confused with variables declared, then there is a way in vim editor to find quick def of that variable.So why u need diff color for variables ?? .
 
Old 11-02-2003, 07:02 AM   #7
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
I've found a solution. The c.vim syntax definition file of vim 6.1 doesn't seem to define "Identifier". To solve it, download an alternative c-language definition file for vim: http://www.eandem.co.uk/mrw/vim/syntax/std_c.zip

unzip it, and copy the extracted ./syntax/c.vim to ~/.vim/syntax. Now you can use lines like this in your own colorscheme file (e.g. ~/.vim/color/mycolors.vim):
Code:
hi Identifier   ctermfg=darkgreen cterm=none guifg=#cd5c5c
Activate your colorscheme ("mycolors") with the vim command:
Code:
:colorscheme mycolors
 
Old 11-02-2003, 07:26 AM   #8
sub_slack
Member
 
Registered: Jul 2003
Distribution: slackware
Posts: 56

Rep: Reputation: 15
or you can use
:syn on
 
Old 11-02-2003, 08:09 AM   #9
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
That will not highlight identifiers, which was the OP's question.
 
Old 11-02-2003, 12:40 PM   #10
new_user10
Member
 
Registered: Jun 2003
Posts: 30

Original Poster
Rep: Reputation: 15
ah - i see. thanks a lot Hko.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
RdHat Vim Syntax Highlighting R4z0r Linux - Software 8 09-06-2011 01:22 PM
vim syntax highlighting problems. donniejones18 Linux - Software 7 04-16-2006 08:03 PM
vim syntax highlighting MiniMe001 Linux - General 2 06-19-2005 11:08 AM
Java syntax highlighting in vim Phantomas Linux - Software 0 08-16-2003 04:34 AM
Vim syntax highlighting NSKL Linux - Software 2 11-09-2002 02:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration