VIM - Vi IMproved  -  Creating your own syntax highlighting file

[ Home - Syntax Files - Rxvt - Dead Keys - Compiling - Ispell - Download ]

First, you need a .vimrc file in your home directory. You can use mine as a guide if you want. The important lines with respect to syntax highlighting are

     " get syntax highlighting
     let mysyntaxfile = "$VIM/mysyntax/mysyntax.vim"
     syntax on
This assumes that you did set the environment variable VIM to point to the vim installation directory. In my case this directory is a subdirectory of my home directory, but most of the files and directories there are symbolic links to the real vim install directory ($VIM/syntax for example points to /usr/local/vim/syntax).

Now you have to create the mysyntax.vim file. I use it to declare the additional colors I can use in rxvt plus I added some lines such that instead of the default syntax color files my own syntax files are loaded. In the latter case you may also want to add some new filetypes as shown in my mysyntax.vim file.

That's all there is to it. Now you should get a colorful screen when you open a java source file for example.

If you want to create a new syntax file for a new language, you need to do the following:

  1. Create a new filetype in your vimrc file. Assuming that your language uses files ending in *.newl you would add
             au BufRead,BufNewFile *.newl set filetype=newlang 
    An entry to read your syntax file is needed too:
             au! Syntax newlang source $VIM/newlanguage.vim
    (make sure that the path is correct).
  2. Now create a file called newlanguage.vim by copying one of the many language files already available. Make the necessary changes and save the file.
  3. Open a source file of your new language and enjoy the color. For a detailed descriptions of the commands used in syntax files check the vim help pages by entering
             :help syntax
    in vim.

(C) 1997-2001 Claudio Fleiner