Ctrl+z suspends Vim so that you are back to where you were when you started Vim.
:sh starts a new shell in Vim's current directory.
Both options have their use.
The other issue I have in general with the ! form is that some applications mess up osx vim. For example, try dropping into a node session (!node) and then quitting.
bind '"\C-z":"fg\n"'
bind -x '"\C-z":"fg"'
echo 'Control-z: "fg\n"' >> ~/.inputrc
If I replace "z" with "a", it works.C-z works otherwise, e.g. C-v C-z prints ^Z in shell, and C-z suspends programs (e.g. vim). Is it a bash thing or a terminal thing (I'm using iTerm2)?
set bind-tty-special-chars Off
in your .inputrc, before you do the bind on C-z.The readline man page is a little misleading:
bind-tty-special-chars (On)
If set to On, readline attempts to bind the control characters treated
specially by the kernel's terminal driver to their readline equivalents.
Disabling it doesn't actually stop readline from binding those control characters. It just enables you to override those default readline binds. If the variable is set to On (the default), that's not possible.Also, another thing I have noticed, is that I cannot catch the SIGTSTP (Control-Z) signal with the `trap` command. I can catch other standard signals, e.g. SIGINT (Control-C), but not SIGTSTP (along with SIGSTOP and SIGKILL, obviously).
I recommended ^Z/fg/bg because it's the fastest, easiest way to get to a good, functional shell if you're not using a multiplexer (tmux/iTerm2). If you map ^Z in your shell to "fg\n" then switching is lightning fast.
Is there any reason to do this instead of !sh within Vim to drop into a shell?