Using vi for multiple files

You can work on multiple files using vi using a single terminal. Suppose I have three files:

- Experiment.php
- Spectrum.php
- Tag.php

To open all three files at once, I would type the following command:

$ vi Experiment.php Spectrum.php Tag.php

This would open all three files show Experiment.php on my terminal. To see the files which are open, I type the following command in vi:

:ls

This would list all the open files. To open yet another file, e.g. Peak.php, I type the following vi command:

:e Peak.php

To verify:

:ls

You should see the Peak.php in this list.

  1 #    "Experiment.php"               line 154
  2      "Spectrum.php"                 line 0
  3      "Tag.php"                      line 0
  4 %a   "Peak.php"                     line 1

A number is listed to the left of each file. This can be used to switch between files. To switch to Tag.php, type:

:bu 3

You can also switch back to the command line without closing any of the files. To do so, type ctrl-z To switch back, type fg.