local options in autocmds apply settings to wrong buffer

0 views
Skip to first unread message

Ben Fritz

unread,
Apr 2, 2009, 12:14:20 PM4/2/09
to vim_use
This simple test case demonstrates my problem:

vim -u NONE -N -i NONE

:autocmd BufRead *.txt setlocal wrap
:view test.txt
:tabe test.c
:setlocal nowrap

Now modify test.txt outside of Vim and give focus back to Vim to
trigger a reload of test.txt.

Vim is still in the test.c tab, so when the BufRead autocmd fires,
'wrap' is set for test.c instead of test.txt.

I'm not sure whether this is supposed to happen or not...if someone
could point me to the proper help section that describes this
behavior, that would be great. It is fairly unexpected, but I doubt it
is a bug.

My actual situation is more complicated. The :setlocal wrap is not in
an autocmd, but rather in $HOME/vimfiles/ftplugin/txt.vim, detected by
file extension in $HOME/vimfiles/ftdetect/txt.vim with the following
command:

au BufNewFile,BufRead *.t{e,}xt,*.log,*.csv,*.err set filetype=txt

I think I should be able to find a way to use <afile> to find the
correct buffer using an autocmd separate from the filetype plugin, but
I'd rather get something working with the plugin file instead. Does
anyone have an idea of how to do this?

Maxim Kim

unread,
Apr 2, 2009, 1:36:22 PM4/2/09
to vim_use
On 2 апр, 20:14, Ben Fritz <fritzophre...@gmail.com> wrote:
> This simple test case demonstrates my problem:
>
> vim -u NONE -N -i NONE
>
> :autocmd BufRead *.txt setlocal wrap
> :view test.txt
> :tabe test.c
> :setlocal nowrap
>
> Now modify test.txt outside of Vim and give focus back to Vim to
> trigger a reload of test.txt.
>
> Vim is still in the test.c tab, so when the BufRead autocmd fires,
> 'wrap' is set for test.c instead of test.txt.
I confirm it. Looks like a bug to me.

Regards,
Maxim Kim.

Ben Fritz

unread,
Apr 21, 2009, 2:41:35 PM4/21/09
to vim_use


On Apr 2, 12:36 pm, Maxim Kim <haba...@gmail.com> wrote:
> On 2 апр, 20:14, Ben Fritz <fritzophre...@gmail.com> wrote:> This simple test case demonstrates my problem:
>
> > vim -u NONE -N -i NONE
>
> > :autocmdBufRead*.txt setlocal wrap
> > :view test.txt
> > :tabe test.c
> > :setlocal nowrap
>
> > Now modify test.txt outside of Vim and give focus back to Vim to
> > trigger a reload of test.txt.
>
> > Vim is still in the test.c tab, so when theBufReadautocmd fires,
> > 'wrap' is set for test.c instead of test.txt.
>
> I confirm it. Looks like abugto me.
>

Any other thoughts?
Reply all
Reply to author
Forward
0 new messages