I have assigned the macro !clear && gcc % && ./a.out to the key 'r'.

So when I press '@r', I expect vim to:

  1. Clear the shell
  2. compile the current C file
  3. run the output

The problem is that it does all three but does not wait at the output screen where it shows "Press ENTER or type command to continue" and comes back to command mode.

  • Please show the exact map command you are using. EDIT: I just saw you use @r so that is a macro and not a map. You have to end the recording of the macro before you press enter at the "hit enter" prompt otherwise that will be part of the macro. (press q before enter).
    – Lucas
    Commented Jul 24, 2018 at 18:24
  • Indeed, it is a macro. Yes, I quit recording before hitting enter, so that isn't the problem. Any other suggestions?
    – Apoorve
    Commented Jul 24, 2018 at 18:50
  • For me this works in vim 8.1.22: @r!clear && seq 200<CR>q (I use seq because I don't have your c program and <CR> is the return key here). The I can later type @r and it executes seq again and stops at the hit enter prompt. Did you set more?
    – Lucas
    Commented Jul 24, 2018 at 19:49
  • I'm sorry, I don't currently have access to the system. I am fairly new to vim so I did not know of the set more command. Will try and confirm. Thanks!
    – Apoorve
    Commented Jul 25, 2018 at 14:20
  • 1
    @Apoorve it works, thanks for the update. Commented Jun 29, 2020 at 21:18

1 Answer 1


I'm not sure what was the problem then, but on Vim 8.1.1600 (on macOS Catalina), the following works for me now.

Example C file:

#include <stdio.h>
int main() {
  printf("%d", 5);
  return 0;

Vim sequence to record the macro-

  1. Ensure you are in normal mode
  2. Press qg to start recording the macro for the key g
  3. Press :w and then press enter
  4. Press :!clear && gcc % && ./a.out (% refers to the current filename)
  5. Press q to stop recording

It is important that at the time of recording the macro, you don't press any key between steps 4 and 5, because this example C does not require any input.

To execute the macro, press @g

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.