I want vim to open Tagbar with :TagbarToggle
when vim is starting up, but only:
- If the file is Python
- If it's not vimdiff
- If I'm not using
vim -O file1.py file2.py
to open multiple windows
I would expect this to work:
if ! &diff && winnr('$') == 1
autocmd FileType python :TagbarToggle
endif
Especially since :echo winnr('$')
in vim does show the number of windows currently open, but adding echo winnr('$')
to vimrc always returns 1, even if multiple windows are being opened with vim -O
.
Is there a different way to check in vimrc if multiple windows are being opened?
I'm pretty sure I can hack together a solution based on timers (timer_start
), where it waits for vim to open a hard-coded amount of time before checking winnr('$')
, but that seems dumb. On slower systems, like a raspberry pi (which I use), the hardcoded value would need to be longer to adjust for longer startup time, but a longer timer on a faster system would be noticeable (the files would open, and half a second later, tagbar would open, which is annoying).
autocmd VimEnter python if (...) | :TagbarToggle | endif
.. is what I'm thinking but that's off the top of my noodle. – B Layer Dec 11 '20 at 19:44