Vim syntax highlighting

software development


I guess this isn’t exactly a programming question, but I figure someone here would be most likely to know.

I haven’t been able to get syntax highlighting working for vim on dreamhost. Syntax is on in my vimrc and “:set syntax” reveals that vim knows the document is php or html or whatnot, but I still get no highlighting.

Also, my putty terminal is showing color on an ls -C (and the vi tildes at the end of the file are bluish), so I don’t think the problem is there.

Anyone else had any luck with this?



vim syntax highlighting isn’t installed. Installations
Go vote :slight_smile: (~10th’ish suggestion).


It’s installed on andor at least… (and some of the other servers I checked) - what does:
% dpkg -S xmath.vim
say on your server?

andor% dpkg -S xmath.vim
vim: /usr/share/vim/vim61/syntax/xmath.vim

does /usr/share/vim/vim61 exist?

If vim is installed at all, syntax highlighting should be enabled. If you’re really unhappy, you can install your own version of vim.

Make sure you’re calling vim as “vim” and not “vi” - vi on most of the DH servers is (intentionally) nvi and not vim.

If I create a script and put a “#!/usr/bin/perl” shebang at the top, and turn syntax on, I see (colored) syntax highlighting.

To the OP - does putting “set bg=dark” change anything?



/usr/share/vim/vim61/syntax/*.vim does exist, but for the life of me I can’t get it to work with :set syntax=php or anything similar.

Doing :set bg=dark doesn’t seem to do anything.
However my xterms are already black background white foreground.

:set bg=light doesn’t seem to do much either…


It appears I’m in the same boat as VxJasonxV. I’m on korben, and all of the vim syntax files are installed, and syntax appears to be working (i.e. “:set syntax” says syntax=php or syntax=vim or syntax=python depending on the file I’m editing), but there’s no color highlighting, even after “:syntax enable” or “:syntax on”. Telling vim I’m using a dark background (":set bg=dark") doesn’t affect the coloring at all, either.

I went and voted for it to see if that helps to clear up the problem.

On korben, by the way, vi points to vim, not nvi.


I’m on Peso, btw.

:syntax enable worked


“:syntax enable” still doesn’t work for me. I’ve got “syntax on” in my vimrc as well.

I have noticed that “:syntax” in the editor returns “No Syntax items defined for this buffer”. “:set syntax” still returns “syntax=php”, etc., as I mentioned in my previous post. Seems vim is unable to find the syntax files.

Aha! Silly me. The vimrc I copied over from another account set runtimepath to /usr/share/vim/vim63. With that line deleted syntax highlighting works.


Sorry for the ludicrous bump, wanted to chime in with stuff.

This is the contents of my ~/.vimrc:
set title
set background=dark
syntax on

And it’s PRETTY :-).

Syntax highlighting is good, and dark makes it even better on a black putty/xterm/whatever.

Were you still never able to get syntax highlighting to work?



Syntax highlighting is working for me now. The error was in the vimrc file I copied from another system. It set runtimepath to point at vim63 instead of vim61. Vim on dreamhost knows where to look without setting the runtimepath in one’s own vimrc, so I deleted the line. Problem solved.

Given the impetus by your message, I trimmed my vimrc down to its essentials. It now reads as follows:

[code]" Personal configuration file for vim

set showcmd
set showmatch
set ignorecase
set incsearch
set autowrite

set tabstop=4
set expandtab
set title

syntax on

if filereadable("/etc/vim/vimrc")
source /etc/vim/vimrc
As you can see, all of the “different from vi” settings are included. I have tabstop and expandtab set for Python. I tried out “set title” after seeing it in your post and it seems useful enough so I’ve added it.

I’m too used to vim’s colors when bg=light to switch to bg=dark, even though I’m probably damaging my eyes squinting at the shadowy letters on the screen. Oh well.



I’ll have to look at those first 5 options, I’ve never used them before.

I like vim’s default tab settings just fine;
And yes, set title is really really helpful.

Glad to hear syntax highlighting is now working for us all!
I think I should contact support and ask them to nuke that suggestion of mine off Home:Suggestions.

One side question, just a picky semantics issue really.
Shouldn’t something like;
if filereadable("/etc/vim/vimrc")
source /etc/vim/vimrc
Be at the start of the .vimrc, so it doesn’t nuke your changes?

Import the system default, then make your customizations?
I see in your case it doesn’t matter… but again, pickiness :).


I did some testing and, yes, sourcing the system vimrc (source /etc/vim/vimrc) at the end of the file does override the changes I’ve made. More testing reveals that settings in the system vimrc (I tested autoindent) apply whether I source it or not, so I think it’s unnecessary.

A few things are puzzling to me, however. First, :set textwidth shows “textwidth=78” when the system vimrc sets textwidth=0. Furthermore, if I put “set textwidth=40” in my vimrc I still get textwidth=78. Second, “set showcmd” gets nuked when I source /etc/vim/vimrc at the end of the file even though it’s commented out in /etc/vim/vimrc, so it shouldn’t be affected one way or the other.

Vim configuration == mysteries upon mysteries. See for example, a long discussion about the complexities of indentation configuration.

ps I just discovered :scriptnames and found “setlocal tw=78” in /usr/share/vim/vim61/ftplugin/vim.vim. I’ll have to explore these files some more and get back to you.


Does anyone know what would cause syntax highlighting to change?

Earlier today I was at home and used my plain old xterm.

(Typically I work from work, and use putty, for being an xterm emulator, PuTTY > *)

I was editting some php scripts, and the highlighting kept changing.
Sometimes it was just html.
Sometimes it was just php.
Sometimes is was actually both.

I really couldn’t understand it, does anyone have any suggestions to how to start figuring out what vim is doing with regards to syntax highlighting?