Reputation: 5498
I have some autocmds which run a Vimscript function. The function is bound to TabEnter
and also BufEnter
.
However when somebody enters a new tab, the function is run several times because both the autocmds fire (and TabEnter
seems to fire BufEnter
with the previous "current" buffer before firing it again with the new buffer...I think).
Anyway, how can I just run my function once when somebody enters a new tab?
Upvotes: 0
Views: 491
Reputation: 5498
I solved this by having:
TabLocal
set a tab-local variable on TabEnter
and then process all the buffers in the new tabBufEnter
look for the tab-local variable; if present, it clears it and does nothing else; if absent, it processes the buffer.Here's my code.
Upvotes: 0
Reputation: 172698
You didn't tell us when exactly your functionality needs to be triggered; maybe your combination of events (TabEnter
and BufEnter
are somewhat unrelated; what if the same buffer is displayed in both tabs?) is off, and the problem could be fixed by choosing other events.
Apart from that, you could:
bufnr('')
) / window (winnr()
) / ... in a script-local variable, and short-circuit your function if it's the samelocaltime()
) and short-circuit when too little time passed:noautocmd
and :set eventigore+=...
could remedy thisUpvotes: 1