Multi-tasking from the Unix shell (vim and mysql cli users, crowd around)
So, you are venturing into the cool crowd by playing with vim. You are a developer that is used to GUI editors and are not really a shell kind of guy/girl. Or, maybe you have been using vim for a while and are just used to closing out a file before moving onto the next one.
Having a background in Linux due to my past experience as a Sr. Oracle DBA in Linux environments, I became a Linux command line guru fast. Using vim as a text editor is very powerful, but what would be even more powerful is being able to switch from file to file quickly and easily. Below, I’m going to give a visual how-to on multi-tasking in a Unix Shell environment.
Typically developers have 2 things open while working. Loads of files and mysql.
First step, let’s open up a file in vim. (vim app/controllers/contact_controller.php)
After it is open hit “Ctrl + z” on your keyboard. This will throw the process in the background

From here, let’s open up mysql (mysql -u user -p) and once we have logged in and gotten to the CLI, let’s hit “Ctrl + z” and throw that process in the the background

You will notice the numbers before the processes (1 & 2). So, now we have these processes in the background. Now what? Ok, so let’s first learn how we can actually see what we have already placed in the background. From the command line, type “jobs” and hit enter.

So, “jobs” gives you a list of background processes. In this case processes 1 and 2. So, now we need to know how to access those processes so we can continue what we were doing. Type “fg <process #>” (ie. fg 2) and press enter.

Isn’t this fun. Just think about when you get used to it, it will be just as fast, if not faster then “Alt + Tab”. From here you can run as many processes as you want. Just follow all of the steps…Ctrl + z to throw a process into the background and fg <process #> to get back in. Simple as that.
I think you will find multi-tasking in Unix is a very simple and productive thing.
Share ThisTags: CakePHP Developers, cakephp development, Unix Developers, Vim ssh
What abount when you lose connection? Ain’t screen a better solution?
December 18th, 2008 at 11:01 am@verbal - thanks for the comment. Screen would be another conversation. But, yes, you could either a) create multiple screens and open a file in each b) create 1 screen and follow my samples above.
But, yes, screen would allow you to not lose anything if you lose connection. Good advice.
December 18th, 2008 at 11:04 amWow never really know about this. But sometimes I wish do have something like this.
A Question: Could I stop a running shell? Something like this:
$ cd /long/and/painful/path
$ bash
$ pwd
/long/and/painful/path
$
$ cd /tmp
$ fg 1
$ pwd
/long/and/painful/path
(it does not work, but is there a way to do this?)
June 27th, 2009 at 8:02 pmVim is able to display multible tabs. Just try :tabnew :tabnext and :tabprev for example
Also if you need on shell with an open vim session and another shell with something else you really should open just two sessions of putty (as I would open another terminal in *nix). Your OS is already able to do multitasking so just do it.
February 10th, 2010 at 5:24 pm