When using vim inside my Bash-shell, I will sometimes use Ctrl-Z to leave vim and do other things in the shell. Later, I will then use the fg command to return to vim. However, it sometimes happens that instead of returning to vim with fg, I start a new instance of vim when I find some file I want to edit. That means I have two instances of vim running in the same shell, and I don't like this idea. I want to force myself to only run one instance per shell.Is there some way I can block vim from starting if one instance is already running in the current shell? Can this be implemented in the .vimrc instead of making a shell script that runs when I type vim?
Prevent vim from starting in a shell if it is already running in background
shell;vim
This in your .bashrc might work, but may hit some false positives:alias vim='if jobs | grep -q vim; then fg; else command vim; fi'