LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2011, 07:29 AM   #1
kartagien
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Rep: Reputation: 0
Smile Vim hightlight Syntax


Hello,
I want to customize my Vim editor to encode and read easily in C,
I actually download the file syntax c.vim so I can color the preprocessor, functions, types ... However I can not color the variables declared.

Please can you tell me how I can do it?
best regards
 
Old 10-10-2011, 07:41 AM   #2
fukawi1
Member
 
Registered: Apr 2009
Location: Melbourne
Distribution: Fedora & CentOS
Posts: 854

Rep: Reputation: 190Reputation: 190
You may need to edit ~/.vimrc and add:
Quote:
syntax on
 
0 members found this post helpful.
Old 10-10-2011, 07:51 AM   #3
kartagien
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Original Poster
Rep: Reputation: 0
thanks for your reply
yes I had changed the vimrc file by adding "syntax on " but by reading c.vim file i can't found a keyword linked to c variables to hightlight it ?
for example in c.vim syntax plugin , I find a keyword as "Function" "Include" ... that i can easly highlight it .

do you understand my problem ?
 
Old 10-10-2011, 11:24 AM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
The problem is that you can only highlight known words, for example the keywords, but not words that are not known. Variable names are simply not known before.
 
Old 10-10-2011, 11:34 AM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by TobiSGD View Post
The problem is that you can only highlight known words, for example the keywords, but not words that are not known. Variable names are simply not known before.
Maybe it's possible to highlight all words that match "[_A-Za-z$][_A-Za-z0-9$]*" (which is the regex for valid C variable names) but are not keywords?
 
Old 10-10-2011, 11:39 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,130
Blog Entries: 2

Rep: Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825Reputation: 4825
I don't know how to exclude the keywords.
 
Old 10-10-2011, 12:09 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by TobiSGD View Post
I don't know how to exclude the keywords.
I figured out that keywords seem to take precedence over regex petterns in Vim syntax files.

This should work:

Code:
syntax match cIdentifier /[_$a-zA-Z][_$a-zA-Z0-9]*/

hi def link cIdentifier Identifier
 
1 members found this post helpful.
Old 10-11-2011, 05:33 AM   #8
kartagien
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Original Poster
Rep: Reputation: 0
This solution work but it highlight all the function keyword also ?
 
Old 10-11-2011, 08:02 AM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720Reputation: 720
Quote:
Originally Posted by kartagien View Post
This solution work but it highlight all the function keyword also ?
C has no "function" keyword. What do you mean?
 
Old 10-11-2011, 10:02 AM   #10
kartagien
LQ Newbie
 
Registered: Apr 2011
Posts: 5

Original Poster
Rep: Reputation: 0
In c.vim classic I have added this to be able to highlight function keyword
Quote:
syn match cCustomParen "(" contains=cParen,cCppParen
syn match cCustomFunc "\w\+\s*(" contains=cCustomParen

hi def link cCustomFunc Function
even I use your suggestions for variables , I highlight function so !!
thanks
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Vim Syntax Highlighter carlosinfl Linux - Software 2 03-25-2010 09:14 AM
VIM Syntax Highlighting JMJ_coder Programming 3 03-05-2008 05:37 PM
ways to set syntax hightlight in VIM vito_huang Linux - Software 6 12-07-2006 07:39 PM
How do I get coloured syntax in ViM? impulse() Linux - Software 2 09-26-2006 10:56 PM
Vim syntax highlighting NSKL Linux - Software 2 11-09-2002 03:39 AM


All times are GMT -5. The time now is 01:10 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration