Bookmark and Share

Split screen in vi

Posted: Tuesday, February 17th, 2009 at 11:20 pmUpdated: Tuesday, December 14th, 2010 at 12:28 pm

This is pretty simple to do. It’s also very usable if you just want to compare 2 files or different sections on the same file. Here’s what you do while in vi or vim.

Split screen horizontally


The above code will split vi horizontally like the screenshot below. You can also supply an optional filename. If you do, it’ll open new file on the second window.
vi horizontal split

Split screen vertically


Unsurprisingly, the above code will split vi vertically like the screenshot below. Just like :split command above, :vsplit will also take optional filename that if supplied will open the named file on the new screen instead.
Vertical split in vi

Navigating between screens

Navigating between split-ed screens is pretty easy in vi. Just type ctrl-w ctrl-w (that is twice ctrl-w) to jump between screens. You can also use ctrl-w then arrow key to move to different screens. This is useful if you split screens into more than 2 like below.
vi 3 split screen

To unsplit / close split-ed screens

This section is suggested by Vic Kovacs, thank you. To unsplit or close a split-ed screens, simply navigate to the screen that you’d like to unsplit / close, then simply type :q to quit editing that screen.

To resize split-ed screens

This section is suggested by Andaluz, thank you. To resize the split-ed screens,

  • For horizontal split, navigate to the screen that you wish to resize, then type ctrl-w then + or – to increase or decrease horizontal size by 1. You can also type the number before hitting ctr-w + / – to resize by the specified number. For example, 10 ctrl-w +, will increase the window size by 10.
  • For vertical split, navigate to the scren that you with to resize, then type ctrl-w then > or < to increase or decrease vertical size by 1. SImilarly, you can also type the number to resize by other than 1.

There you have it. And as always, I welcome comments / questions / critics that will help me and other readers understand better.

14 Responses to “Split screen in vi”

  1. Vic Kovacs Says:

    I advocate adding how to unsplit screens to get back to a single window.


  2. Maresa Says:

    Thank you Vic … I’ve added a section to unsplit to get back to a single window.

  3. Milktrader Says:

    Thanks for the unsplit explanation. I was searching all over for that tidbit

  4. Andaluz Says:

    Can you also tell us how to resize a splitted window? I did + or -, but I couldn’t resize a splitted window more to the left or more to the right.

  5. Maresa Says:

    Thank you for asking this. I’ve updated the post to include how to resize split screen. 🙂

  6. Ian Says:

    Helpful post, thank you! After looking around for a bit, I stumbled on equal resizing of both windows, whether they were split or vsplit: ctrl-w =

  7. Maresa Says:

    @Ian: Thank you. It’s very useful addition.

  8. Hetaswi Says:

    Useful post.

  9. unixrefresher Says:

    thank you. very useful to me. 🙂

  10. proby Says:

    Hi , when editing all the frames get edited , how to open multiple files ?

  11. Maresa Says:

    @proby : When creating new frame, you can specify filename. The frame will then open and will edit that file. Alternatively, once you split, you can then just type :e to change the current frame to open a different file.

  12. PypeBros Says:

    I noted the use of :only that seems to be emacs \’CTRL-X 1\’ equivalent and \’:new\’ that splits on a blank file.

  13. adobe Says:

    Excellent post. I certainly appreciate this site.
    Continue the good work!

    My blog post; adobe

  14. pip Says:

    vim-tiny seems to not include :vsplit

    How can I install this functionality only?

Leave a Reply

Time limit is exhausted. Please reload the CAPTCHA.