Keeping it Small and Simple

2007.05.14

Quick Vim-tip: getting vim to know .zsh files

Filed under: Vim — Lorenzo E. Danielsson @ 07:09

I’ve been asked this question quite a few times, so I thought I might as well add it here, just in case it helps someone out there..

You may have noticed that Vim supports zsh files, but that files with the extension .zsh don’t get their syntax highlighted by default. That is simple to fix (as with most things in Vim). Simply add this to your ~/.vimrc:


autocmd BufNewFile,BufRead *.zsh setlocal filetype=zsh

Once you have added this, you can try something like vim somefile.zsh. The zsh ftplugin should now be loaded, and you should get your syntax highlighted. This of course assumes that you have enabled syntax highlighting (syntax on) as well as file-type plug-ins (filetype plugin on).

You can use the same principle for other files or file patterns as well. In my vimrc file you will find the following line:


autocmd BufNewFile,BufRead vimoutlinerrc setlocal filetype=vim

because I use the Vim outliner, and vim doesn’t (yet) recognize the file vimoutlinerrc to be a vim file.

An alternative to adding a bunch of autocmds to your vimrc would be to use modelines (see :help modeline if you don’t know what a modeline is). But I personally don’t like to add modelines to my files. Feel free to use which ever solution suits you best.

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: