VIM infoFri 12 March 2010
I was setting up nagios at a new job, and found myself in a position
where all I have is vim to select, copy, and paste text(don't ask, I use
evilwm). I came across this useful bit of info from This
page on creating splits or
multi-file editing in VIM.
The below text is copied from the above link.
Opening a file in a split
Assuming you are already editing a file in a vim session and want to split the screen and edit a second file, you can use either of these commands:
:sp filename Splits the screen horizontally and opens filename in the new area. :vsp filename Splits the screen vertically and opens filename in the new area.
For most purposes, horizontal splits are easier to manage. Any split can be further split -- you can edit as many files in a single instance of vim as you like.
Once you are editing multiple files, you will probably need to move back and forth through your files and manage the size of the splits so that you can see the relevant portions of the files you're interested in.
The prefix for all the below commands is -- that is, hold down Ctrl and type w. Press before typing any of the below commands.
Moves to the next split. k Moves to the split above the current split. Up Moves to the split above the current split. j Moves to the split below the current split. Down Moves to the split below the current split. + Increases the size of the current split by one line. (Try combining this with counts -- e.g. 5+ will make the split five lines bigger.) - (Minus sign) Decreases the size of the current split by one line. _ (Underscore) Maximize the current split (that is, make it take up as much room as possible.)
Saving and quitting
Each split acts something like an individual instance of vim -- so :w
work on the current split. If you want those commands to apply to all the splits instead of just the current one, add a to them --
for instance, :wa
saves all the open files, :qa
quits all open files (and exits vim), and :wqa saves and then closes all open files.