next up previous contents
Next: Spell Checking Up: The Woodnotes Guide to Previous: End of Line Characters   Contents

Multiple Windows, Buffers, and Frames

Remember that what you would call ``files'' in other programs are ``buffers'' to emacs. That distinction becomes important when we start dealing with multiple buffers and introduce the concept of windows and frames (for a quick review look at figure 1).

First of all, let's say you begin working on a file called one.txt. But you want to work on two.txt as well, maybe because you're going to cut and paste text from one file to the other. So once you've got one.txt on your screen, type C-x C-f two.txt. The second file should be loaded into a buffer and that buffer should be the active one. What happened to one.txt? It's still in memory, but your window/frame is only presenting you one buffer, and it's two.txt. You can switch between the two buffers by hitting C-x b. Emacs will ask you ``Switch to buffer (default one.txt). By simply pressing enter emacs will switch to one.txt. Alternatively, you can hit the tab key, and emacs will divide into an upper and lower section, and one section will show a list of all possible buffers. Some are special emacs buffers like logs. *Messages* is an example of one. You can type the first few letters of the buffer you want to switch to and emacs will auto-complete for you. When you've chosen the buffer you want to work on, press enter. By default emacs will assume you want to work on the buffer you were dealing with last, which means it's easy to switch between two buffers simply by hitting C-x b and return, accepting the default.

If you want to see a list of all buffers currently in use, type C-x C-b. You'll see a window listing all current buffers in use.

Once you've got two windows open though, how do you get rid of the second one? There are several ways.

Let's look at some other ways you can deal with multiple buffers and windows. Hit C-x 2 to divide the current window in two pieces, one upper and one lower (two vertical windows). Because emacs doesn't know what else to do, both windows will at first show the same buffer, so if you're currently working on one.txt and split the window, you'll have one.txt in both the top and the bottom windows, and both will reflect changes made in the other (think of them as viewports looking onto the same area of memory). This can be very useful when you want to have on the screen at the same time two different areas of your text.

Hit C-x 3 to divide a window into two side-by-side (horizontal) windows. This can be handy to view side by side two buffers, for example to compare them or look for changes in one. But if you enable follow-mode the two side-by-side buffers will show consecutive sections of the same buffer, and scroll together as you move up and down. On modern, wide screen monitors, this is a great way to maximize how much of your text you can see at once.

Needless to say, you can have different buffers in each window. Start with one window and then using C-x 2 divide it into two windows. Now switch to the other window with C-x o and then open up a new buffer with C-x f (to deal with a new file) or C-x b (to deal with an already opened file). Use C-x k to ``kill'' a buffer (close it permanently; emacs will ask if you want to save changes first) or C-x 0 to close a window without closing the buffer. Now is it clear why it's important to understand the difference between files, buffers, and windows?

A frame is what other programs call a window so be careful to distinguish with your vocabulary. An emacs frame is like a detached window, and like windows, just provide a viewport to a buffer, so you can add and delete additional frames without affecting buffers at all. Needless to say, the concept of a frame only works if you're using emacs in a graphical environment. If you're working at a virtual console, frames are not available to you.

Type M-x find-file-other-frame. Emacs will ask you for the name of the file and then open it up in a new frame. Or type M-x new-frame to display the current buffer in a new frame.

Figure 15: Windows/Buffers/Frames
\begin{figure}\begin{tabular}{ll}
Keystroke & Command/Function  \hline
C-x b &...
...zontally \\
C-x k & Kill buffer (close the file) \\
\end{tabular}
\end{figure}


next up previous contents
Next: Spell Checking Up: The Woodnotes Guide to Previous: End of Line Characters   Contents
Randall Wood 2011-03-31