Bookmark and Share

Split screen in vi

Posted: Tuesday, February 17th, 2009 at 11:20 pmUpdated: Saturday, May 8th, 2010 at 7:04 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

:split

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

:vsplit

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.

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

3 Responses to “Split screen in vi”

  1. Vic Kovacs Says:

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

    Vic

  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

Leave a Reply

Security Code: