75

When working with multiple files, it would be very handy if we can see more than one file in the screen at once. Is there any way in Vim to split the window (horizontally or vertically) so each split can show a different file?

65

Yes, vim has the ability to split both horizontally using :split and vertically using :vsplit which both work just like :edit for opening a file, except they open it in a horizontal / vertical split respectively.

Additionally, I would recommend to also read :h window-move-cursor for moving around different splits with ease.

17

Yes, there are the :split (split into two windows, top half and bottom half) and :vsplit (left and right) commands. You can then use Ctrl-W direction to switch windows (where direction is one of the normal hjkl cursor movement keys, or the arrow keys).

You can then :edit (etc.) a different file in each window.

Full documentation is at :help windows.txt.

16

You can either split vim windows by opening multiple files using -o, -O, -o2 parameters.

Or if you're already editing multiple files in one window, you can use :ba to split horizontally or :vert ba to split vertically.

:[N]ba[ll] [N] :[N]sba[ll] [N] Rearrange the screen to open one window for each buffer in the buffer list.

:vert[ical] {cmd} Execute {cmd}. If it contains a command that splits a window, it will be split vertically.

To quit, use: :qa.


See also:

7

You can use :split or :vsplit for horizontal and vertical splits respectively. Provide the path to the file you want to open to open a specific file. Or just type the command to open a copy if the current file.

You can then move between splits using C-w + hjkl.

  • 12
    A shortcut for a horizontal split is :sp, with the vertical shortcut being :vsp. – bronzehedwick Feb 3 '15 at 17:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.