How could I exit Vim, not :q, and then go back to continue editing?
10 Answers
Assuming terminal Vim on a flavor of *nix:
To suspend your running Vim
Ctrl + Z
will suspend the process and get back to your shell
fg
will resume (bring to foreground) your suspended Vim.
To start a new shell
Start a subshell using:
:sh
(as configured by)
:set shell?
or
:!bash
followed by:
Ctrl+D (or exit, but why type so much?)
to kill the shell and return to Vim.
9 Comments
ps to view foreground processes unix.stackexchange.com/questions/6115/…nodemon app.js (nodemon refreshes the server on file edits for you) and then I want to return to my vim editing. Can I do that without two separate terminal windows?jobs to visit the foreground processes with a (to me) more readable title. Then eg fg %2 to select the second.control-z acts as 'undo' check your vimrc to see if behave mswin is present. If it is remove it and control-z will workexitYou can use :sh to exit to your default shell then typing $ exit at the shell prompt will return you to Vim.
3 Comments
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.
Comments
You can also do that by :sus to fall into shell and back by fg.
If you frequently need to go back and forth between shell and vim, probably what you really want is have only one vim instance in the shell, and use it to open any file in the workspace. If so, check this question. Once you set it up correctly, you can :sus or C-z to return to the shell, then just v or v <newfile> to get back to vim.
And my answer is almost my daily routine.
Comments
If you're using Neovim, you can do the following:
:terminalcommand to bring up a terminal window.- Do your terminal stuff
- Type
exitto kill the terminal process - Press any key to return to Neovim
Comments
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:
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.
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.
Comments
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>