On 2009-02-24, Raúl Núñez de Arenas Coronado <[email protected]> wrote:
> Hi all:)
>
> I want to automatically modify the format of the attribution line and
> some details of the signature when replying to emails. This can be done
> using a couple of simple "s" commands. My problem is on the
> "automatically" part...
>
> For doing the "automatic edition" I've set an autocommand:
>
> autocmd BufRead *.eml /pattern/s/something/otherthing/
>
> I've put this in "~/.vim/after/ftplugin/mail.vim
>
> The *.eml file are properly detected as "mail" and the rest of lines of
> "~/.vim/after/ftplugin/mail.vim" are properly executed. In fact, the
> autocommand appear when doing ":au BufRead *.eml", but the autocommand
> is not run.
>
> Just in case the problem was on the command, I tried this:
>
> autocmd BufRead *.eml echo "BufRead hit!"
>
> Still, it doesn't work.
>
> I don't want to use "BufEnter" because after the substitution has been
> done it won't match again, so it doesn't make sense running the auto
> command every time I enter the buffer.
>
> What am I doing wrong? Is BufRead the problem and then I should use
> another event? Is the placement the problema and I should put the
> autocommand in another file? Given that I only want to do the
> substitution once at the beginning: should I get rid of autocommands and
> do the job directly in "~/.vim/after/ftplugin/mail.vim" (which is what
> I'm doing right now)?
The problem is your use of an autocommand within an ftplugin file.
Ftplugin files are sourced as a result of a FileType autocommand,
which was triggered by a BufNewFile or BufRead autocommand.
Therefore, by the time the ftplugin is read, the filetype-dependent
autocommand event has already occurred; any filetype-dependent
autocommand defined in your ftplugin won't be triggered.
If you want to execute some command as a result of loading a
particular type of file, EITHER put the command in a filetype
plugin, OR put the command in an autocommand in your ~/.vimrc.
Don't use an autocommand in a filetype plugin.
The only reason to use an autocommand within a filetype plugin is to
catch some event that occurs after the filetype plugin is sourced.
In your particular case, just put
/pattern/s/something/otherthing/
in ~/.vim/after/ftplugin/mail.vim, as you said you're doing at the
moment.
Regards,
Gary
--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---