LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 02-18-2004, 12:33 AM   #1
TastyWheat
Member
 
Registered: Aug 2003
Location: Texas
Distribution: Knoppix 5.0.1, Fedora Core 5
Posts: 66

Rep: Reputation: 15
Adding Syntax Highlighting to VIM


I want to set up vim so that it will give me special syntax highlighting for
html template files. These are almost exactly like regular html files, but there are {variable} tags added that are parsed by php. When I choose html as the syntax format it treats the tags like normal text. I want those tags to be specially highlighted in VIM.

Adding syntax highlighting is not an easy process, but probably only need to add one line to the syntax file. I tried it myself but it didn't work. I want the tag to be highlighted (in red I guess) dispite anything it's in between, not including HTML comments. So I guess it would look like this:

<html>
<body bgcolor="{body_bgcolor}" text="#000000">
<!--- {this} shouldn't be highlighted differently --->

{this} should be highlighted differently

</body>
</html>

The only problem that might come about is with scripts and stylesheets because they use '{' '}'. However, the {tags} should only contain letters, numbers, and underscores. Does anyone know what I need to add in order to do this? Or does anyone have a link that clearly explains syntax highlighting?
 
Old 02-18-2004, 08:00 AM   #2
DrOzz
Senior Member
 
Registered: May 2003
Location: Sydney, Nova Scotia, Canada
Distribution: slackware
Posts: 4,185

Rep: Reputation: 60
<html>
<body bgcolor="{body_bgcolor}" text="#000000">
<!--- {this} shouldn't be highlighted differently --->

{this} should be highlighted differently

</body>
</html>

this is how mine looks when i type what you have shown ...
so since "by default" mine are already red, then i guess my suggestion to you is to use the default .vimrc file ...

now since you use redhat, and i use slack, all i can do is tell you where this is located on my slack box ..
the command i have to type to use this file is the following :
cp /usr/doc/vim-6.2/doc/vimrc_example.vim /home/USER/.vimrc


i hope this helps ...
 
Old 02-27-2004, 03:37 AM   #3
TastyWheat
Member
 
Registered: Aug 2003
Location: Texas
Distribution: Knoppix 5.0.1, Fedora Core 5
Posts: 66

Original Poster
Rep: Reputation: 15
Well, I went ahead and made a new syntax file for my templates. It took a long time to get right, but it's the way I want it now. I used the html syntax file and just edited it around so it highlights things in braces differently. I didn't really need it in red, I just chose that color because it isn't a very common color in highlighted html files. Actually, I fixed it so that the template variables have a different background color. I can't really show it on here, but these are the lines I added:
Code:
syn region tplVariable     start=+{+     end=+[}\n]+     contains=tplVariablePart,tplVariableError
syn match tplVariableError     contained +[^}^{\W]+
syn match tplVariablePart     contained +\w+
hi tplVariable     guifg=White     ctermfg=White     gui=Inverse cterm=Inverse
hi tplVariablePart     guifg=White     ctermfg=White     gui=Inverse cterm=Inverse
hi tplVariableError     guifg=DarkRed     ctermfg=DarkRed     gui=Inverse cterm=Inverse
The first line sets the region (beginning and end) for the variable and tells it to interpret tplVariablePart and tplVariableError differently. Otherwise anything from { to } is just a regular tplVariable. The second line sets all non-words (excluding braces) as an error inside the tplVariable. That's a personal decision because I think the variables can be composed of almost anything. The third line sets all alphanumeric characters (including underscores) to be the body of the tplVariable. The last three lines just set up the colors for the first three lines. So any errors come up as black on dark red, and a correctly formated variable is black on white. In order to get this working properly I think you'd also have to add tplVariable to the "contains" field of other syntax regions (like strings).

I've pretty much gotten the hang of this syntax thing so let me know if I need to elaborate on any of this.
 
  


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 MiniMe001 Linux - General 2 06-19-2005 11:08 AM
How to make vim has syntax highlighting ICO Linux - General 4 01-05-2004 10:35 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 > Linux Forums > Linux - Software

All times are GMT -5. The time now is 01:38 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