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
  • 86,445
  • 63
  • 260
  • 306
ysap
  • 2,620
  • 12
  • 50
  • 74

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
  • 19,383
  • 5
  • 58
  • 71
  • Thanks for the answer. Putting this on the startup file did not mean to be something permanent, just me playing with the startup files and the newly discovered confirm() function. I was just surprised to see this behaviour. Your solution on Edit Two makes sense (and was confirmed by @IngoKarkat). – ysap Mar 22 '14 at 17:33
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
  • 22,638
  • 2
  • 45
  • 58
  • Thanks. You're probably right. Your solution was also suggested by @Heptite. I just wonder if this should be reported as a bug, as he suggested (probably not, as this is expected assuming the GUI really get restarted after the init scripts). – ysap Mar 22 '14 at 17:36
  • A reply to a bug report by Braam Moolenaar confirms that this is an expected behaviour. – ysap Mar 25 '14 at 09:26