On 2010-07-03, John Little wrote: > Daniel D Jones wrote: > > Using Gvim under Gentoo Linux, if I open a file with a .txt extension, > Gvim > sets the filetype to text and sets the appropriate word wrap, etc. > that I have > configured. But if I open Gvim, create a new buffer with :tabnew and > then save > that as a file with a .txt extension, Gvim doesn't set the > filetype... > > Gary replied: > > Vim assumes that you want to determine the file type when a file is > > opened or a new buffer is created, i.e., before you start viewing or > > editing, not when you write the file. > > I think that's quite wrong. I put > > au! BufRead,BufNewFile *.txt setfiletype text > > in my ~/.vim/filetype.vim according to :help new-filetype part C, and > upon :tabnew, :save (or :write) the file type is set to text.
I stand corrected. I don't understand why the 'filetype' is being set, though. Some experimentation suggests that the BufRead event is being triggered by the :w command, but only when the BufRead autocommand is within the filetypedetect group. I don't get that from reading ":help BufRead" and it doesn't make sense to me. Why does writing a file trigger a BufRead event? Regards, Gary -- 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
