1

In Vim, I use the Startify plugin. There's a few ways to open new Vim tabs with this plugin; and I would like to configure my Vim to ensure that :tcd %:h is executed automatically for the first buffer opened into a new Tab after executing Startify.

For purposes like this, Startify provides the StartifyBufferOpened autocmd. Unfortunately, this is executed for every buffer that you open with Startify. Similarly, I'm aware of Vim's built-in TabNew; but this fires any time a new tabpage is created; I only want to :tcd in the tabpages created by Startify.

Is there a VimScript function I could construct that would, when evaluated in several new buffers (i.e. by StartifyBufferOpened), only actually run a particular command if a new tabpage was just created for that buffer?

ELLIOTTCABLE
  • 17,185
  • 12
  • 62
  • 78
  • 1
    Is it a performance problem to do `:tcd` for every buffer? Unrelated: if I pop 2 buffers in a tab, which directory should I use? – D. Ben Knoble Jan 04 '20 at 05:04
  • 3
    `if winnr('$') == 1 | tcd %:h | endif` – Matt Jan 04 '20 at 06:56
  • @D.BenKnoble Ah, if it was unclear, I specifically wanted to set the working-directory by the *first* buffer opened into a new tab, and leave it unmodified by later buffers opened into that tab (including my own window-managmement post-Startify) – ELLIOTTCABLE Jan 04 '20 at 23:40

0 Answers0