Can Vim kill its parent process?

I know a child could not kill a parent process in Linux, but how can I achieve :!exit in Vim?

I would like to exit directly from Vim out of the terminal without semi-step of exiting Vim first. How can I achieve that?

  • 2
    If you start Vim as exec vim then it will replace the shell process with the Vim one, so when you quit Vim there is nothing left and the terminal will close. I'm not sure if I 100% follow your question, but I think this is what you want? Commented Jun 2, 2020 at 13:43
  • @MartinTournoij so, but no. My purpose is to close terminal upon :!exit, because you exit from terminal when you issue $exit command. The same I want to achieve from vim
    – Herdsman
    Commented Jun 2, 2020 at 13:49
  • 1
    What do you want to happen to Vim when you run :!exit? Do you want to exit that too, or keep it running? Commented Jun 2, 2020 at 14:35

2 Answers 2


This is not possible directly from Vim. This is something that has to be done in the calling shell.

You could work with a shell function:

# Vim and optional exit
    vim "$@" || exit

If Vim returns a non-zero exit code, the command exit is called to exit the shell and hence close the terminal.

To produce a non-zero exit code use :cq instead of :q. If Vim would return a non-zero exit code for any other reason, the terminal would also close.

BTW: Your :!exit can't work, as it is not executed in the shell started by the terminal emulator, but in a shell started by vim.

  • What does :c do anyway? Cannot find in :help :c
    – Herdsman
    Commented Jun 2, 2020 at 18:01
  • 1
    @Herdsman See :h :cq.
    – Ralf
    Commented Jun 2, 2020 at 18:05

@Martin Tournoij has the best answer so far. If you edit your .bashrc and add :

alias V='exec vim'

Then when you start vim with 'V [filename]' the terminal will close when you exit vim. If you start vim with 'vim [filename]' then the terminal will not close when vim exits.

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.