4

This is probably just a bandaid for a greater problem, but I had the following code for MacVim (GUI mode) in my .vimrc

autocmd GUIEnter * winpos 100 50

The problem is it's not working properly on startup, yet if I run winpos even 1 second after it starts it works perfect.

The GUIEnter command seems to be correct from all I read, and it's still doing GUI stuff after this obviously, because it keeps moving the window just a bit from where I want it.

Is it possible as a hacky workaround to let MacVim load completely, wait 200ms and then execute the winpos command?

4
  • You can try to use sleep (:h :sleep) but you said so: the problem is probably elsewhere.
    – statox
    Feb 2, 2018 at 17:02
  • As :help GUIEnter says It is triggered before VimEnter when using gvim., you should give VimEnter a try. And maybe also FocusGained
    – mMontu
    Feb 2, 2018 at 17:17
  • sleep wont work because it prevents Vim from loading in the first place like its frozen
    – Tallboy
    Feb 2, 2018 at 17:38
  • I tried FocusGained and VimEnter as well but no dice :(
    – Tallboy
    Feb 2, 2018 at 17:38

1 Answer 1

11

In recent vim versions, you can use timer_start to delay an operation. For example, to execute winpos 200 milliseconds after vim starts,

autocmd VimEnter * call timer_start(200, { tid -> execute('winpos 100 50')})
1
  • So awesome, that worked! 8ms did the trick :)
    – Tallboy
    Feb 2, 2018 at 17:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.