BufEnter buggy?

36 views
Skip to first unread message

Aaron Bohannon

unread,
Sep 28, 2013, 6:03:39 PM9/28/13
to vim...@googlegroups.com
I have an autocmd that updates the window title in my terminal based on the current file name. BufEnter clearly seems to be the event I would want to trigger it with. But I've noticed two problems:

(a) BufEnter isn't getting triggered after closing the last window in a tab and ending up in a different tab. It *should* be getting triggered, right? I mean, it gets triggered when I close a window and end up in a different window in the same tab, so why wouldn't it get triggered when I close a tab?

(b) When switching directories in netrw (which switches buffers), BufEnter gets triggered before the directory location is known, so expand('%') will be empty. But once I'm in the directory, I get the directory location just fine by calling expand('%'), so I'm not sure how netrw is changing the buffer location *after* the BufEnter event. It seems like there's some questionable logic going on there, but I'm not sure who's to blame.

...Aaron

Christian Brabandt

unread,
Sep 29, 2013, 9:06:54 AM9/29/13
to vim...@googlegroups.com
Hi Aaron!

On Sa, 28 Sep 2013, Aaron Bohannon wrote:

> (a) BufEnter isn't getting triggered after closing the last window in
> a tab and ending up in a different tab. It *should* be getting
> triggered, right? I mean, it gets triggered when I close a window and
> end up in a different window in the same tab, so why wouldn't it get
> triggered when I close a tab?

Are you sure? I can't replicate it. I don't see a message when doing
:au BufEnter * :echom "BufEnter triggered!"
But that seems to be related to the redrawing (since the old tabpage is
closed), but the event fires, nevertheless.

Best,
Christian
--
Es gibt kaum einen Menschen, von dem man nichts lernen kann.
-- Chinesisches Sprichwort

Aaron Bohannon

unread,
Sep 29, 2013, 1:58:45 PM9/29/13
to vim...@googlegroups.com
Yeah, I couldn't get any definitive information from :echo/:echom either. So I did this:

autocmd BufEnter * let g:foo = expand('%')

And then I'd check the value of g:foo with :echo after switching/closing windows.

Christian Brabandt

unread,
Sep 30, 2013, 12:06:01 PM9/30/13
to vim...@googlegroups.com
On Sun, September 29, 2013 19:58, Aaron Bohannon wrote:
> So I did this:
>
> autocmd BufEnter * let g:foo = expand('%')
>
> And then I'd check the value of g:foo with :echo after switching/closing
> windows.

Now I am confused. Does this work for you yes or no?

regards,
Christian

Aaron Bohannon

unread,
Sep 30, 2013, 8:44:38 PM9/30/13
to vim...@googlegroups.com

The autocmd that sets the variable does not get run when I close the last window on a tab page. It is easy to check that it _does_ get run in other circumstances.

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

---
You received this message because you are subscribed to a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rIDzIjQ04sc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Vlad Irnov

unread,
Sep 30, 2013, 10:43:35 PM9/30/13
to vim...@googlegroups.com
On 9/28/13, Aaron Bohannon <aaro...@gmail.com> wrote:
> I have an autocmd that updates the window title in my terminal based on the
> current file name. BufEnter clearly seems to be the event I would want to
> trigger it with. But I've noticed two problems:
>
> (a) BufEnter isn't getting triggered after closing the last window in a tab
> and ending up in a different tab. ...

Which Vim version are you using? I remember such bug being reported by
someone and it was subsequently fixed before version 7.4. It can be
tested as follows:

tabnew Foo
autocmd BufEnter <buffer> let g:foo+=1
tabmove
tabnew
let g:foo = 0
wincmd c
echo g:foo

The output is:
0 (wrong) in Vim 7.3.829
1 (correct) in Vim 7.3.145, Vim 7.4.000

Regards,
Vlad
Reply all
Reply to author
Forward
0 new messages