Tutorial
Vim (vi Improved)
Working with Multiple Files; Crash Recovey; Marking Your Place
Vim
Working with Several Files
There are numerous ways to work with several files in vim; we will introduce them as the situation appropriate to each arises.
- For the program above, since the three files (source file and the two data files) are independent of each other (i.e., we don't
expect to be cutting/pasting between any pair of them), we can simply use separate ssh windows and have separate instances of vi running in each.
- We can accomplish this using the
Window/New Terminal
menu selection of ssh; alternatively there's a button on the ssh toolbar that looks like the
ssh Client icon that is on your desktop.
Recovering an Edit from a Crash
Bad thing happen to good people — if vim crashes, or your ssh client loses the connection, you can recover your edit by going back to the directory and executing:
vi -r <filename>
where <filename>
is the name of the file you were editing (not the swap file name or anything else — vi takes care of all that behind the scenes.
All you need to say is that you wish to recover your edit session.)
Multiple Windows
You can create multiple windows on the vi screen; here are some useful commands:
split
creates a new (horizontal) window, with both the new and the old containing the file you were editing (you can do this more than
once). Guess what vsplit
does?
new <filename>
is basically a split with the specfied filename loaded into the new window.
Ctl-W
is the prefix in normal mode for most window-related commands-- for example, you can follow this with a directional movement key (e.g. j
or
the down arrow) to move into the window in the specified direction.
:q
/ ZZ
Ctl-W c (not sure of the difference)
Marks - Remembering Where You Were
m<lower case letter>
marks (remembers the current cursor position.
'<lower case letter>
jumps to the corresponding mark.