0

Does something like this exist?:

let @p = "0D:!ping -c1 8.8.8.8\<CR>"<SLEEP 1 SECOND>"\<CR>iJust pinged a DNS Server\<ESC>"

  • And let me read the ping result. So things like gs are not possible...
4
  • Is there a reason to not do :read !ping … instead?
    – D. Ben Knoble
    Commented Jul 20, 2023 at 16:44
  • @D.BenKnoble Why should I use the read command? I don't want to write the output of the ping command... Or am I missing something?^^
    – Bog
    Commented Aug 7, 2023 at 6:06
  • You could then do :read !ping, gs, :delete or something similar (plus it would be in your buffer, so you could also just show the results and edit as desired).
    – D. Ben Knoble
    Commented Aug 7, 2023 at 14:51
  • Ahhh interesting approach. I am gonna try that one out^^
    – Bog
    Commented Aug 8, 2023 at 8:52

2 Answers 2

1

To address your requirement of being able to read the output, I'd move the delay into the shell command:

:let @p = "0D:!ping -c1 8.8.8.8 ; sleep 1\<CR>iJust pinged a DNS Server\<Esc>"

I don't think there's any other way of introducing a delay into the middle of Vim's :! command: control doesn't return to the macro until after it's completed and the output has been removed from the screen.

Alternative solutions would be to use D. Ben Knoble's suggestion of reading the output into the buffer itself and then removing it again after the delay, or to move everything into a function where you can do whatever you like and then (if necessary) call this from the macro. This would be a cleaner solution.

3

You can use the gs command to introduce a delay. This command can be prefixed with a count to specify the number of seconds. Refer to the help page for more information. For example, to introduce a 2 second delay, you can use the following:

let @p = "0D:!ping -c1 8.8.8.8\<CR>2gsiJust pinged a DNS Server\<Esc>"
4
  • No this doesn't work. I obviously want to read the ping Prompt. So before the <CR> not after^^ But thanks for showing me that I can replace ^M with \<ESC> :)
    – Bog
    Commented Jul 20, 2023 at 14:42
  • Why is your answer getting upvoted?? It does not work >:(
    – Bog
    Commented Jul 20, 2023 at 15:34
  • 1
    @Pixelbog I'm guessing it's because it answers the general requirement of how to introduce a delay into macro playback, and because you edited in the bit about wanting to read the output later.
    – Rich
    Commented Jul 25, 2023 at 10:44
  • @Rich I thought that it is self explanatory that I want to read the output of my ping command :(
    – Bog
    Commented Aug 7, 2023 at 6:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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