Vim highlighting for specific file types (where to put syntax files, vim events, line to put into vimrc)

Did you try this..

  • Put your jak.vim in .vim/syntax folder
  • put the following lines only in your .vimrc file.
syntax enable
au BufRead,BufNewFile *.jak set filetype=jak
I tried this with your jak.vim file.... It worked fine for me....
I am using vim7.2...
edit:
Try this,
I had the same problem with those mkview and loadview lines... just set filetype once in the file and it will be retained then

Open the file, then do ":set ft=jak", save the file and quit vim.... Now reopen the file... syntax highlighting should work now...
mkview and loadview seems to save the last syntax highlight settings also....


I must admit, I don't know for certain how useful this would be to you... But...

http://beerpla.net/2008/04/02/how-to-add-a-vim-file-extension-to-syntax-highlighting/

I have appended the text incase the page is taken down... Or altered...

How To Add A File Extension To vim Syntax Highlighting Posted by Artem Russakovskii on April 2nd, 2008 in Databases, Linux, Programming 24 delicious saves 2 diggs Share 3retweet

Updated: July 8th, 2009

Today I was asked a question about defining custom extensions for vim syntax highlighting such that, for example, vim would know that example.lmx is actually of type xml and apply xml syntax highlighting to it. I know vim already automatically does it not just based on extension but by looking for certain strings inside the text, like

After digging around I found the solution. Add the following to ~/.vimrc (the vim configuration file):

1 2 3 syntax on filetype on au BufNewFile,BufRead *.lmx set filetype=xml After applying it, my .lmx file is highlighted:

Same principle works, for instance, for mysql dumps that I have to do from time to time. If they don't have a .sql extension, you'll get something like:

After

1 2 3 syntax on filetype on au BufNewFile,BufRead *.dump set filetype=sql everything is fine:

But why and how does it work, you ask?

:help au :au[tocmd] [group] {event} {pat} [nested] {cmd}

Add {cmd} to the list of commands that Vim will execute automatically on {event} for a file matching {pat}. :help BufNewFile When starting to edit a file that doesn't exist. :help BufRead When starting to edit a new buffer, after reading the file into the buffer. :help filetype will actually tell this whole story in part B. And that's how you do it, folks.


I tried reproducing what you've done, but couldn't get the filetype applied to other extensions.

I also found that this helped:

The Vim help-file for 'new-filetype' mentions creating your own 'filetype.vim' in ~/.vim/filetype.vim and writing your auto commands in that file:

if exists("did_load_filetypes")
  finish
endif
augroup filetypedetect
  au! BufRead,BufNewFile *.jak      setfiletype jak
augroup END

All those syntax and highlight commands from your jak.vim need to stored under ~/.vim/syntax, so copy it to ~/.vim/syntax/jak.vim (without the au command).

You'll also have to quit Vim and restart to pick up the changes.


I think things might be twisted around, but I'm no vim expert.

Your syntax highlighting file should be in the syntax directory. The things in nsharish's advice might be what goes into the file you place inside of ftdetect.

This part:

au BufRead,BufNewFile *.jak set filetype=jak

In .vimrc, you may also need to add a line like:

au! syntax jak source $VIM/syntax/jak.vim

IMHO, it makes more sense this way. I hope this helps.