Using VI To Edit Two Files In A Split Screen

April 13, 2007

Sometimes you need to edit a new or existing file while looking at a separate file using VI. This can be very useful and a powerful time saver. Fortunately you can do this using some simple commands.

First go ahead and edit a file with VI

shellprompt$ vi test-1.txt

while in VI enter the following


This will open a new split screen session, in order to navigate between the two windows in VI do the following




Using the first will move you to the lower window and using the latter will move you to the upper window.

To make one of the windows full screen and out of the dual screen mode use the following


*Important Side Notes

If you used :new and opened up a new window session it will not have a name so you cannot save it without entering the following

:wq whatevername.txt

Also if you want to open a file in split screen mode that is not new and exists you can enter the following

:new /path/to/whateverfile

Happy Editing!

Comments for “Using VI To Edit Two Files In A Split Screen”

  1. ak commented on March 11, 2008


  2. webneer commented on June 2, 2008

    Thank you for the tip! Previously, I’ve covered searching text inside a list of text files: Search inside text files in Linux

    Hope it also helps this blog readers.

  3. really awsome!!
    i was expecting same and i got this one

  4. DN commented on October 14, 2011

    Else without a SPLIT Window one can do the following to edit 2 files in full screen mode.

    a. Open the first_file

    b. :e second_file

    c. :e# will enable switch between first and second file

    d. just doing “:e” also restores the file to original mode unless “:w” or any kind of write has been done already.

  5. Robert commented on May 17, 2012

    Thanks for the tips. If you want to split the window, you can use :vsplit and switch between the windows using TRL-w l and CTRL-w h.