[vim] How to temporarily exit Vim and go back

How could I exit Vim, not :q, and then go back to continue editing?

This question is related to vim

The answer is


If you are on a Unix system, Ctrl + Z will suspend Vim and give you a shell.

Type fg to go back. Note that Vim creates a swap file while editing, and suspending Vim wouldn't delete that file (you aren't exiting Vim after all). On dumb terminals, this method was pretty standard for edit-compile-edit cycles using vi. I just found out that for me, gVim minimizes on typing Z.


There are several ways to exit Vim and have everything the same when you return. There is very good documentation within Vim itself explaining the various ways this can be done. You can use the following command within vim to access the relevant help page: :help usr_21

To give you a brief summary, here are the different methods of quitting and returning with your session intact:

  1. Suspend and resume - You don't actually quit Vim with this; you simply hide your session in the background until you need it. If you reset your computer or issue a kill command to Vim, you will lose your session. This is good for when you want to switch to another task temporarily, but if this is the case, then you might want to look into using the GNU Screen utility instead.

  2. Sessions - This is the true way of saving your session between instances of Vim. Even if you truly quit Vim, your session will be there for you when you return. This is probably what you are looking for.


If you don't mind using your mouse a little bit:

  • Start your terminal,
  • select a file,
  • select Open Tab.

This creates a new tab on the terminal which you can run Vim on. Now use your mouse to shift to/from the terminal. I prefer this instead of always having to type (:shell and exit).


Just put in fg and go back to your most recently suspended program.


If you're using Neovim, you can do the following:

  • :terminal command to bring up a terminal window.
  • Do your terminal stuff
  • Type exit to kill the terminal process
  • Press any key to return to Neovim

You can use :sh to exit to your default shell then typing $ exit at the shell prompt will return you to Vim.


To extend user Zen's answer, you could add the following line in your ~/.vimrc file to allow quick toggling between Bash and Vim:

noremap <C-d> :sh<cr>

You can switch to shell mode temporarily by:

:! <command>

such as

:! ls

You can also do that by :sus to fall into shell and back by fg.