How does vim recognize file type?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How does vim recognize file type?

Andrea Spadaccini
Hello,
I am using tablatex.vim, ftplugin for LaTeX files, and I have a main
latex file and several included .tex files.

Well, vim loads the plugin (and the syntax file) when I'm editing the
main file, while it doesn't when I'm editing the included files.

How can I tell vim that I'm editing a .tex file? And how do I make vim
recognize .tex files without me setting the filetype?

TIA,

--
[ Andrea Spadaccini - a.k.a. Lupino - from Catania - ICQ #: 91528290 ]
[ GPG ID: 5D41ABF0 - key on keyservers - Gentoo GNU / Linux - 2.6.17 ]
[ Linux Registered User 313388 - @: a.spadaccini(at)catania.linux.it ]

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How does vim recognize file type?

Samuel Wright
In your vim folder you probably have a filetype.vim which has a couple
of lines per file type to detect when an extension is opened or
created, and set the filetype automatically.

Sam

On 18/09/06, Andrea Spadaccini <[hidden email]> wrote:

> Hello,
> I am using tablatex.vim, ftplugin for LaTeX files, and I have a main
> latex file and several included .tex files.
>
> Well, vim loads the plugin (and the syntax file) when I'm editing the
> main file, while it doesn't when I'm editing the included files.
>
> How can I tell vim that I'm editing a .tex file? And how do I make vim
> recognize .tex files without me setting the filetype?
>
> TIA,
>
> --
> [ Andrea Spadaccini - a.k.a. Lupino - from Catania - ICQ #: 91528290 ]
> [ GPG ID: 5D41ABF0 - key on keyservers - Gentoo GNU / Linux - 2.6.17 ]
> [ Linux Registered User 313388 - @: a.spadaccini(at)catania.linux.it ]
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How does vim recognize file type?

Andrea Spadaccini
Ciao Samuel,

> In your vim folder you probably have a filetype.vim which has a couple
> of lines per file type to detect when an extension is opened or
> created, and set the filetype automatically.

Thanks, I modified it and it works like a charm! :)

--
[ Andrea Spadaccini - a.k.a. Lupino - from Catania - ICQ #: 91528290 ]
[ GPG ID: 5D41ABF0 - key on keyservers - Gentoo GNU / Linux - 2.6.17 ]
[ Linux Registered User 313388 - @: a.spadaccini(at)catania.linux.it ]

signature.asc (196 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: How does vim recognize file type?

Benji Fisher
On Mon, Sep 18, 2006 at 12:50:59PM +0200, Andrea Spadaccini wrote:
> Ciao Samuel,
>
> > In your vim folder you probably have a filetype.vim which has a couple
> > of lines per file type to detect when an extension is opened or
> > created, and set the filetype automatically.
>
> Thanks, I modified it and it works like a charm! :)

     The standard advice is *not* to modify any files under $VIMRUNTIME,
including the filetype.vim that comes with the standard vim
distribution.  One reason is that any changes you make will be lost when
you upgrade to a new version of vim.

     If your files end in .tex and are not being recognized as LaTeX
(i.e., the 'filetype' option is not being set to "tex") then the
simplest solution is probably to add the line

        let tex_flavor = "latex"

to your vimrc file.  See

:help ft-tex-plugin

HTH --Benji Fisher
Reply | Threaded
Open this post in threaded view
|

Re: How does vim recognize file type?

Charles E Campbell Jr
In reply to this post by Andrea Spadaccini
Andrea Spadaccini wrote:

>I am using tablatex.vim, ftplugin for LaTeX files, and I have a main
>latex file and several included .tex files.
>
>Well, vim loads the plugin (and the syntax file) when I'm editing the
>main file, while it doesn't when I'm editing the included files.
>
>How can I tell vim that I'm editing a .tex file? And how do I make vim
>recognize .tex files without me setting the filetype?
>  
>
Vim recognizes file types using two files:  (assuming 7.0)

   vim70/filetype.vim
   vim70/scripts.vim

The "filetype.vim" file recognizes filetypes based on the files'
extension (ie.  .c is a C file, .lsp is a Lisp file, etc).
The "scripts.vim" file recognizes filetypes based on the files' contents
(ie. the first line is /bin/ksh, so its a shell file, etc).

If you wish to customize this process to recognize personal extensions
as some filetype or to recognize file contents as indicating some
filetype, make a personal   (wherever)/.vim/filetype.vim  -or-  
(wherever)/.vim/scripts.vim  with appropriate recognition code.  Look at
the vim70 versions for ideas about how to accomplish this.   Caveat:
*don't* change the distributed vim70/filetype.vim or
vim70/scripts.vim.   If you do, your emendations will no longer be
working and you'll make yourself a lot of irritating work trying to find
out why.

Regards,
Chip Campbell

Reply | Threaded
Open this post in threaded view
|

Re: How does vim recognize file type?

Tim Chase-2
> Caveat: *don't* change the distributed vim70/filetype.vim or
> vim70/scripts.vim.   If you do, your emendations will no
> longer be working and you'll make yourself a lot of irritating
>  work trying to find out why.

I can speak from experience on this matter...In my naive early
days of using Vim6.0, I modified these files.  It held me back
from upgrading for a couple years because all of my changes would
be lost.  I finally bit the bullet and upgraded to a more recent
version (gotta love reformatting to make Windows happy).  By now
adhering to the standards Dr. Chip suggests, I've been able to
automatically upgrade several times with no impact in my personal
preferences.

-tim


Reply | Threaded
Open this post in threaded view
|

Help with errorformat

Jack Donohue
In reply to this post by Benji Fisher
I've got errors that look like:

[cpp.bll/mail/javac]
L:\PCC601\impl\fes.02\pcc.impl\lwp\cpp.bll\mail\src\com\ibm\pcc\bll\mail\components\MailPreferences.java:354:
warning: createWmmDelegate() in
com.ibm.workplace.people.wmm.workspace.WmmDelegateFactory has been
deprecated
[cpp.bll/mail/javac]             WmmDelegate wmmd =
WmmDelegateFactory.INSTANCE.createWmmDelegate();
[cpp.bll/mail/javac]
^

(three lines starting with [cpp.bll/mail/javac])

I'm not too concerned about the multiline syntax, I just want to be able to
parse the first line containing file and line number info.  I played around
with this a bit and came up with:

set efm=[cpp.bll/mail/javac]\ %f:%l:\ %m

which works but only for the package cpp.bll/mail.  What I really wanted was
something like:

set efm=[%s]\ %f:%l:\ %m

where it would just gobble up an arbitrary string between the braces, but
this doesn't work.  So how should one do this?

Thanks,


Jack