2

I want to create a function which would have the same behavior as for example :tabs (the screenshot is in french but I'm sure most of you will see what I mean):

tabs command screenshot

I for now I have the folowing command which works partially:

function! MyFunction()
    echo "foo"
    echo "bar"

    let test = input("Press Enter or input a command", "", "command")
endfunction

The output is shown until the user input something but the behavior is not exactly the same as the one of the built-in functions:

  • With my function the line Press Enter or input a command will stay on screen whereas with the built-in functions when the user press a key the blue sentence on my screenshot disappears to let the command prompt appearing.

  • Also I'll have to create my own code to execute the command entered by the user if he enter one.

So my question is: Is there a "default" way to keep the ouput of my vimscript function in the command line windows on the bottom of the screen until the user press Enter or input a new command?

I would be surprised if every function with an output had to redefine this behavior but I couldn't find how it is done.

  • echomsg is your friend. See also :help interactive-functions. – Sato Katsura Aug 2 '15 at 7:28
  • @SatoKatsura: I'm not sure using echom wouldn't change the behavior of the "pause" after the message and the user has to use the command :messages to see what was output which isn't very convenient in my opinion. – statox Aug 2 '15 at 12:23
  • echomsg messages are persistent, echo ones are ephemeral, they're gone at the next refresh whether you managed to see them or not. The point is, you should probably adapt what you want to do to the way Vim works, rather than trying to do it the other way around. – Sato Katsura Aug 2 '15 at 16:59
  • Maybe "persistent" wasn't the best word to describe what I meant: I just wanted to get the line waiting for a user input (and VanLaser answer was excatly the explanation I needed). But you're right echom are more persistent. Also I can't agree more with you when you say that I should follow the way Vim works, that's what I'll try to do ;-) – statox Aug 2 '15 at 17:48
3

Aren't you complicating things? The message "Press ENTER or type command to continue" is shown by Vim everytime the command line height (which can be set with cmdheight option) isn't enough to display the entire command output. So, for example, for me it's sufficient to define and call this function:

function! ShowSomething()
    echo "blah\nblah\nblah\nblah"
endfunction

:call ShowSomething()

... to have the behavior you want (of course, I could also issue the echo command directly).

enter image description here

  • Oh it seems that my cmdheight was set at 4 and my function output 3 lines so I didn't get the message and as I didn't know that was an automatical behavior I didn't understand why I didn't get it. Thank you! – statox Aug 1 '15 at 13:45
  • You're welcome :) – VanLaser Aug 1 '15 at 13:45

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.