Is there a way to not execute a command, once I have pressed Ctrl+X Ctrl+E? (edit-and-execute-command)

Ideally like in git: If I save the file (like :wq in vim), it gets executed, but if I close the file without saving, (like :q! in vim), the command doesn't get executed.

  • @doneal24 ^x^e is bound to edit-and-execute-command. I think this is standard, but I've updated the question now. Commented Jan 21, 2022 at 19:30
  • 1
    @Quasímodo thank you! I didn't know about cq! If you add an answer I will mark it as accepted. Commented Jan 21, 2022 at 19:30
  • 1
    Can't you just delete everything and save a blank file?
    – terdon
    Commented Jan 21, 2022 at 20:19
  • ctrl-x-e without executing command immediately. Then you ctrl+c. Commented Jan 21, 2022 at 23:47
  • 2
    Why not just comment out the command in the editor? Commented Jun 23, 2022 at 17:46

2 Answers 2


To cancel execution of the command, completely erase the contents of the file before saving it and quitting the editor.

Interestingly, using this method, the original unedited command is still saved in the history.

Note: this answer was suggested in a comment -- I tested it and it works.


Even in the course of normal line editing, I've cultivated the habit of putting a # prefix at the beginning of the line. This allows me to look over a complex command to ensure that it's correct, or perhaps to save a "draft" of a command in my history while I go research some other point of information that I need to formulate and check the precise syntax of the draft command.

Presuming you're editing just a one-line command, from within vi, do:


Then save the file, and your "draft" command will not be executed, but will be stored in your bash history. When you're ready, you can return to the command, remove the leading # and execute the command.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .