Chapter 11. Multiple Windows in Vim

By default, Vim edits all its files in a single window, showing just one buffer at a time as you move between files or to different parts of a single file. But Vim also offers multi-window editing, which can make complex editing tasks easier. This is different from starting multiple instances of Vim on a graphical terminal. This chapter covers the use of multiple windows in a single instance of a running Vim process (which we’ll call a session).

You can initiate your editing session with multiple windows or create new windows after a session starts. You can add windows to your edit session up to the limit imposed by sanity, and you can delete them back to a single edit window.

Here are some examples where multiple windows make your life easier:

  • Editing a number of files that need to be formatted the same way, where you would like to compare them visually as you go along

  • Cutting and pasting text quickly and repeatedly among multiple files or multiple parts of a single file

  • Displaying one part of a file for reference, to facilitate work elsewhere in the same file

  • Comparing two versions of a file

Vim offers many window-managing convenience features, including the ability to:

  • Split windows horizontally or vertically

  • Navigate from one window to another and back again quickly

  • Copy and move text to and from multiple windows

  • Move and reposition windows

  • Work with buffers, including hidden buffers (to be described later)

  • Use external tools such as the diff command ...

Get Learning the vi and Vim Editors, 7th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.