Skip to content

Instantly share code, notes, and snippets.

@jackfranklin
Created December 28, 2013 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackfranklin/8160205 to your computer and use it in GitHub Desktop.
Save jackfranklin/8160205 to your computer and use it in GitHub Desktop.

Often I jump from Vim -> Command Line by backgrounding Vim with Ctrl-Z, doing my CLI stuff, and then going back to Vim with vi (which is just aliased to vim).

Sometimes though, I'll forget about my backgrounded Vim, and end up having another Vim process running.

How can I make my vi alias work such that:

  • if there is a Vim process backgrounded, just foreground into that
  • if there is not, load up vim as normal.

Thanks in advance!

@mheap
Copy link

mheap commented Dec 28, 2013

At the bottom of your .zshrc:

vi() {
if [[ `jobs|grep vi|wc -l| tr -d ' '` -ne "0" ]]; 
then fg;
else vim; 
fi
}

Caveat: Only works if vim was the last thing backgrounded. I'll work one one that detects the right job later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment