Gary Johnson-4 wrote:
> 
> If you want to find out what is setting 'ft', execute this:
> 
>     verbose set ft?
> 
>> does 'filetype on' command behave differently from the .vimrc vs. the 
>> command line?
> 
> The command itself behaves the same regardless of where it is
> executed.  The effect of executing it may vary depending on when it
> is executed relative to other commands that define autocommands.
> 
> Executing ":filetype on" loads the file $VIMRUNTIME/filetype.vim
> (see ":help :filetype") and that file executes a whole lot of
> autocommands that respond to the BufNewFile and BufRead events and
> execute the :setf command in response.  Conceptually, Vim maintains
> a list of autocommands for each autocommand event.  When an event
> occurs, Vim traverses the list of autocommands for that event and
> executes any whose patterns match.  The autocommands are executed in
> the same order as they are added to the list.
> 
> What that means is that if you execute an autocommand, e.g.,
> 
>     au BufRead *.c setf python
> 
> and then execute
> 
>     filetype on
> 
> your autocommand will precede those loaded by ":filetype on" and
> will be executed first whenever a file ending in ".c" is read.
> 
> In the case of the :setf command, the first one executed in response
> to a single event wins.  Following my example, executing
> 
>     :e foo.c
> 
> where foo.c already exists will result in 'filetype' being set to
> "python".
> 
> Now, if instead you executed those commands in this sequence,
> 
>     :filetype on
>     :au BufRead *.c setf python
>     :e foo.c
> 
> 'filetype' would be set to "c".
> 
> If you used "set filetype=python" instead of "setf python", like
> this,
> 
>     :filetype on
>     :au BufRead *.c set filetype=python
>     :e foo.c
> 
> then 'filetype' would be set to "python" because "set
> filetype=python" is executed last and because the :set command
> forces an option to be set unconditionally whereas :setf sets the
> 'filetype' conditionally as described in
> 
>     :help :setf
> 
> That's a lot of information.  The points are that:
> 
> 1.  ":filetype on" defines a set of autocommands;
> 2.  autocommands are executed in the order in which they are
>     defined;
> 3.  :setf sets the filetype conditionally (the first one in a
>     sequence wins);
> 4.  ":set ft=" sets the filetype unconditionally (the last one in a
>     sequence wins); and
> 5.  (not discussed above) modelines are executed after any BufRead
>     autocommands.
> 
> I hope understanding that will help explain what you've been
> observing.
> 
> Regards,
> Gary
> 
> 

wow, i had a busy weekend, so i just read now your response.
really appreciate that.thanks

alex

-- 
View this message in context: 
http://old.nabble.com/set-filetype-in-.vimrc-tp28931594p28944864.html
Sent from the Vim - General mailing list archive at Nabble.com.

-- 
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

Reply via email to