On this page I give a description of how I managed to get syntax highlighting working for JML documents in VIM. I use VIM 6.1 at the moment.
Before you continue I must warn you that:
java.vim
file.
Basically you should either take it as it is or improve it and send your improved version to me.
Well, basically all you have to do is follow the VIM manual (:help syntax
)
MAKING YOUR OWN SYNTAX FILES When you create your own syntax files, and you want to have Vim use these automatically with ":syntax enable", do this: 1. Create your user runtime directory. You would normally use the first item of the 'runtimepath' option. Example for Unix: mkdir ~/.vim 2. Create a directory in there called "syntax". For Unix: mkdir ~/.vim/syntax 3. Write the Vim syntax file. Or download one from the internet. Then write it in your syntax directory. For example, for the "mine" syntax: :w ~/.vim/syntax/mine.vim Now you can start using your syntax file manually: :set syntax=mine You don't have to exit Vim to use this. If you also want Vim to detect the type of file, see |new-filetype|. If you are setting up a system with many users and you don't want each user to add the same syntax file, you can use another directory from 'runtimepath'.
If you use the file jml.vim instead of mine.vim
you should be able to view the highlighting that I have setup.
If you like using this syntax highlighting feature, you are probably also interested in automatically loading this syntax file. From the VIM manual we learn that this is how that works:
This explains the details that happen when the command ":syntax enable" is issued. When Vim initializes itself, it finds out where the runtime files are located. This is used here as the variable |$VIMRUNTIME|. ":syntax enable" and ":syntax on" do the following: Source $VIMRUNTIME/syntax/syntax.vim | +- Clear out any old syntax by sourcing $VIMRUNTIME/syntax/nosyntax.vim | +- Source $VIMRUNTIME/syntax/synload.vim from 'runtimepath' | | | +- Setup the colors for syntax highlighting. If a color scheme is | | defined it is loaded again with ":colors {name}". Otherwise | | ":runtime! syntax/syncolor.vim" is used. ":syntax on" overrules | | existing colors, ":syntax enable" only sets groups that weren't | | set yet. | | | +- Set up syntax autocmds to load the appropriate syntax file when | | the 'syntax' option is set. | | | +- Source the user's optional file, from the |mysyntaxfile| variable. | This is for backwards compatibility with Vim 5.x only. | +- Do ":filetype on", which does ":runtime! filetype.vim". It loads any | filetype.vim files found. It should always Source | $VIMRUNTIME/filetype.vim, which does the following. | | | +- Install autocmds based on suffix to set the 'filetype' option | | This is where the connection between file name and file type is | | made for known file types. | | | +- Source the user's optional file, from the *myfiletypefile* | | variable. This is for backwards compatibility with Vim 5.x only. | | | | | +- Install one autocommand which sources scripts.vim when no file | | type was detected yet. | | | +- Source $VIMRUNTIME/menu.vim, to setup the Syntax menu. |menu.vim| | +- Install a FileType autocommand to set the 'syntax' option when a file | type has been detected. | +- Execute syntax autocommands to start syntax highlighting for each already loaded buffer.
So the important step is setting up the autocommands in filetype.vim
for the JML extension.
I did this by putting filetype.vim in ~/.vim
.
At some places you hear that you have to include some lines in your .vimrc
or .gvimrc
file in order for this to work.
However, I have used it without these files and it works.
This last line hurts a bit since it is not really VIM like, but it is possible to add this JML syntax to the Syntax Menu.
For this I had to do two things. First I put a file menu.vim in the ~/.vim
directory.
After that I changed my $HOME/.vimrc in such a way that it 'sources' the new menu.vim
file.