Vi lacks in providing a way to edit multiple files at the same time, but Vim offers an option to do so.
If you open several files via the command line, you can switch between those files with the edit-command (:help edit):
vim file1 file2 file3 :e file2 " edit file2 :e# " edit alternate file -- file1![]()
Using :e you can read the file (given as parameter) into the current buffer. Vim will save an alternate filename with the symbol #. As it can be seen in line 3, # stands for file1 (the "alternate filename") in this case.
Ok... this will load files "between" others and you can display one after another, but is actually very stupid. In most cases, when I'm programming and need to open 2 files, in general I need to write (modified) text from one file to another. In this case I want to have both files side by side. This is done with the split command:
:sp file1
This command will split the screen into two parts: one with the current buffer and one file with file1. To split files vertically, use the "vsp"-command. To handle this frame-separation anyway, you have to use the following commands. All of them require a <C-W> before.
| <C-W> | Move to next frame. |
| k | Move to frame located above the current. |
| Up | (see above) |
| j | Move to frame located beyond the current split. |
| Down | (see above) |
| + | Increases the size of the current frame by one line (eg. 5<C-W>+ will make the split five lines bigger.) |
| - (Minus sign) | Decreases the size of the current frame by one line. |
| _ (Underscore) | Maximize the current frame (that is, make it take up as much room as possible.) |
See :help split for more information about this issue.
Recent Comments