1

I am using gVim's confirm() function to pop a dialog waiting for the user to click a button. However, there seems to be a difference in the appearance of the dialog when called from .gvimrc:

Using the command: :let MyTestV = confirm("IN MY_GVIMRC") generates the following dialog:

enter image description here

When this line (sans the :) is added in a .gvimrc (and the .vimrc as well) file, the following appears when a new gVim is opened:

enter image description here

Note that the dialog appears before the actual gVim window appears on the screen.

1) Why is there a difference in the appearance of the two dialogs?

2) Where can I put the command so that the dialog appears as expected?

Oliver Salzburg
  • 89,072
  • 65
  • 269
  • 311
ysap
  • 2,730

2 Answers2

1

I suspect this is a variant of the typical "race condition" class of bugs. Start a non-GUI version of Vim and run your confirm() command and you'll see where the extra text comes from. Basically, Vim is putting the non-GUI confirm() text into the GUI popup because, at the time of your .vimrc being run the GUI isn't actually available yet.

I suggest you email bugs at vim.org (address slightly obfuscated to slow down spambots) with a report about this. You could even link to this SuperUser question.

Edit: This problem is even worse than I suspected. I decided to see if I could reproduce it and I put this command in my .vimrc:

echo confirm('test')

And I got the same result you did, but with an extra line added consisting of 1 which is the return value of the confirm() function. Something is definitely wrong here.

Edit Two: If delaying your confirm() dialog is not a problem you could do this instead:

autocmd VimEnter * let MyTestV = confirm("IN MY_GVIMRC")
Heptite
  • 20,411
1

I think you're running into undefined behavior; functions that interact with the user are not supposed to be executed from ~/.vimrc, as the GUI hasn't been properly initialized yet. :help input() contains a warning:

NOTE: This function must not be used in a startup file, for the versions that only run in GUI mode (e.g., the Win32 GUI).

If you need to query something from the user immediately after startup, use :autocmd VimEnter to trigger it.

Ingo Karkat
  • 23,523