Saturday, July 28, 2012

Re: Filetype detection on vim

On 27/07/12 12:49, ansuman wrote:
> Hi,
>
> I am not getting how to add a new filetype to vim. I am on windows and I am
> using vim73.
>
> I want to add a new filetype with extention .pn. For this I had done
> following:
>
> I went to vim installation directory i.e. vim73 and I edited filetype.vim. I
> added following line
>
> au BufNewFile,BufRead *.pn setf potion
>
> in between augroup filetypedetect and augroup END

Don't change anything in $VIMRUNTIME or below, any upgrade (next week or
10 years from now) may revert your changes without warning.

>
> Then I opened my vim with a file with extension .pn.
> I typed following command
> :set filetype?
> and got answer
> filetype=
>
> Am I doing any wrong?
>
> Please help.
>
> Thanks
> Ansuman

What I recommend is to add a new filetype.vim in one of the following
places (shown as they would appear in Vim):

- Single-user on Windows
$HOME/vimfiles/filetype.vim
- Single-user on Unix, Linux, Mac OSX, etc.:
$HOME/.vim/filetype.vim
- For all users on any OS
$VIM/vimfiles/filetype.vim

(create the directory if it doesn't yet exist); with the contents:

if exists('did_load_filetypes')
finish
endif
augroup filetypedetect
au BufNewFile,BufRead *.pn setf potion
augroup END

The above is from section C under :help new-filetype

You should also drop one or more of the following scripts (found
somewhere or written by you) in the following subfolders of the
directory containing your new filetytpe.vim:

ftplugin/potion.vim
syntax/potion.vim
indent/potion.vim

If you don't have them, Vim may recognise your new filetype but it won't
know how to handle them. AFAIK none of those scripts are distributed
together with Vim, you'll have to find them elsewhere.

And finally, you should make sure that there is a :filetype command with
the approprite arguments somewhere in your vimrc.

See :help :filetype

After all this is done, restart Vim so that your changes take effect.



Best regards,
Tony.
--
When you're not looking at it, this fortune is written in FORTRAN.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments: