Thursday, October 10, 2013

Re: Avoiding gvim message box from echomsg in vimrc

On 10/10/2013 06:02 AM, Tony Mechelynck wrote:
> On 09/10/13 18:02, Crestez Dan Leonard wrote:
>> My vimrc sometimes does echomsg on startup. With console vim I get a
>> "Press ENTER" prompt, which is OK. With GUI vim I get a modal message
>> box instead. I want to get rid of that message box but still preserve
>> the messages (in the :messages prompt). I particularly dislike the fact
>> that if echomsg later I don't get a message box, this seems very
>> inconsistent.
>>
>> I tried to set guioptions+=c. With vim-gnome I no longer get a message
>> box, but I get a double "Press ENTER" prompt with no visible messages.
>
> I also am on gvim with gtk2/Gnome2 and my 'guioptions' is set to gimrLtc
> but I don't see the above symptoms. My 'cmdheight' is set to 2, see below.

I took a closer look and it seems that it matters if gvim's stdout
isatty() or not. This is true when running from a terminal but false
when running through a gnome launcher (or a windows shortcut).
Apparently when stdout is not a tty vim will attempt to show early
:echomsg in a GUI message box.

Here a sample.vimrc:

echomsg "aaa"
echomsg "bbb"

- If I run this with gvim -u sample.vimrc in a terminal I get
"aaa\nbbb\n" on stdout.
- If I run gvim -u sample.vimrc &> some_file I get a GUI messages box
with two lines.
- If I add set guioptions+=c in the sample.vimrc and run gvim -u
sample.vimrc &> some_file I get a double "press enter" prompt but no
message box.

> Are you sure there are no syntax errors, and no Floats, Dictionaries or
> Lists, in the arguments of your :echomsg? Also, see in the help the
> difference between :echo and :echomsg in the treatment of unprintable
> characters.

Yes. I can reproduce with just :echomsg "hello world".

>> With windows vim this seems to have no effect. Is this a bug?
>>
>> Using :silent or plain :echo would work, but I want to keep the messages.
>>
>> I think the best solution would be to have a scriptable way to clear the
>> "Press ENTER" prompt and any random point, but I found no way to do this.
>
> Try
>
> if &cmdheight < 2
> set ch=2
> endif
>
> This should avoid the hit-ENTER message when the message is only a
> single line.
>
> See also :help :echo-redraw

I tried both increasing cmdheight and :redraw, but it does not seem to
have any effect. My guess is this happens because these are messages
from vimrc, before everything is completely initialized? If I call a
function which does 3 echomsg and a redraw! at runtime then it behaves
as you say, in both console vim and gvim.

Maybe I should move my init code to some autocmd instead.

--
Regards,
Leonard

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: