About Emacs Buffers and windows

Source: Internet
Author: User

The "buffer" of Emacs is separate from the window or frame.
The Emacs "window" We see is not the window of Emacs, but the graphical window frame of emacs (GUI windows frames). Before the graphical window is available, Emacs can already be run in "terminal", in the terms of windows, the "console" program.
Essentially, windows and frames are just tools for displaying buffer content. The buffer can contain the contents of the file, which can be customized within Emacs, such as *messages*,*scratch*, or *help*, or it can be customized by the user and the content is not written to the file.
Emacs's way of separating the buffer from the graphics window is powerful and flexible. We use C-x b for most of the time to switch buffers, which is easier than using a mouse switch or slicing windows in multiple frames, although they have advantages in some cases.
There are three ways to learn about the buffers in Emacs and their details:
1. C-x c-b, display buffer list;
2. The buffer menu, which lists the open buffers and the shortcut commands that guide them;
3. In the Emacs window, press the CTRL key and click the left mouse button to eject the buffer list.

Emacs defines some buffers by itself, their names, usually in a format like *buffername*,*help*,*scratch*, and the buffer list itself is an emacs custom buffer.


When we start Emacs, we generate two buffers of *messages* and *scratch*. *messages* is a buffer used to display all command information from the start of Emacs, *scratch* is a draft buffer where we can scribble things, but will not be saved unless the user uses the C-x c-w command.

When you use Emacs to edit a file, the files you read are copied to the buffer area of the same name. If the user needs help, you can also open the *help* buffer. There is no limit to the number of buffers that can be opened. Most of the time, only one or two buffers are shown, and a lot of them exist even though we don't see them. We can think of buffers as a bunch of pages, where only one page is the current page. Of course, we can switch to make a page, or create a new page. Each buffer is associated with a main mode, which determines the behavior of Emacs within that buffer. For example, text mode, which is designed to write documents, Lisp mode is used to write Lisp programs. Users can display multiple buffers in an Emacs window or frame, and it is important to remember all the buffers that you created.

Working in multi-buffer mode
If you want to create a buffer that contains the contents of a file, you can c-x C-f,emacs automatically creates a buffer and enters it. If a copy of this file has been opened in a buffer, then C-x c-f will enter the existing buffer. If the user wants to open a file that does not exist, Emacs creates a new file buffer and enters it.
Here's what to keep in mind:
C-x C-f is to open a file that is always followed by this directory/file name, and if the file to be opened does not exist, create a new file.

Toggle Buffer
To move between different buffers, use c-x B. Emacs will provide us with a default name for the recently hidden buffer, which can be entered by a carriage return. or enter the name of the buffer we want to enter the first few words, and then press the TAB key, Emacs will automatically fill the full buffer name for us, enter can be entered.
C-x,b followed by the name of a buffer. If the corresponding buffer does not exist, Emacs will automatically create a new empty buffer. Unlike C-x C-f, the new buffer is not associated with a file, and Emacs does not remind us to save the buffer when it exits Emacs.

The following two options are available for viewing the buffers that are already open:

1. C-x C-b, this method can be used in the terminal environment of Emacs;
2. In the Emacs window, press the CTRL key and click the left mouse button. This method is only valid for graphical Emacs.

Delete buffer
Cause: One is the buffer in Emacs too much, want to get rid of a few, the second is the modification of the existing document is catastrophic, the buffer will be killed.

To remove a buffer, type C-x K,emacs to display the currently displayed buffer name, or type the name of the buffer you want to delete, and then enter. If a buffer has been associated with the file and the content has changed, Emacs will prompt us to save it. In other cases, the buffer will disappear forever. and typing m-xkill-some-buffers can delete the buffer in batches, the system will be an enumeration of existing buffers, asked if we kill it, we just need to answer ' yes ' or ' no ' on it. When all buffers are killed, Emacs will not be empty, and it will create a new *scratch* buffer.

Working in multiple windows
A window is an area on the screen that displays the contents of the Emacs buffer. You can open more than one window at a time, each window can display a different buffer, or you can display different parts of the same buffer, where there is no overlay, just a split screen. Once you create a new window, the old window shrinks automatically. Just like the screen is pie, you can cut it into chunks, but these windows are arranged in only two ways: horizontal or vertical.

Create a horizontally arranged window
The most commonly used command is C-x 2, which allows you to split the current window horizontally into two windows, repeating the command repeatedly and splitting out more windows. We can also have Emacs open multiple windows each time it starts. If we need to edit two documents in a horizontally segmented two window, you can specify the names of these two files when you start Emacs. For example, I want to edit abc.txt and 123.html two different documents, when starting Emacs, you can directly emacs Abc.txt 123.html. If you edit more than two documents, Emacs displays the last portion of the document you specified in one window, and then gives a list of buffers in another window.

You can use C-M-V to scroll through the screen of another window in one window.

Migrating between multiple windows
To switch the cursor from one window to another, you can c-x o (o = other). In the graphical emacs, you can use the mouse to switch windows.

Remove the window
To delete the currently located window, you can c-x 0. To delete all the windows, just keep the current window, you can c-x 1. Alternatively, you can delete a batch of windows as you would delete a buffer, m-xdelete-windows-on. But deleting a window simply means that it is no longer displayed and does not delete any information in the buffer, and we can still use c-x B to switch to the buffer we need.

Several shortcut keys:

Shortcut keys Command Function
C-x b Create buffer or toggle buffer (determined by the presence of the input buffer name)
C-x F Open the file and read it into the buffer

C-x s

Save buffer ('-' Save buffer, ' n '-not save buffer, '! ') -Save all buffers, '. ' -Saves the current buffer buffer only, ' Q '-cancels the save instruction and does not save the current buffer.
C-x s after performing c-r Read-only way to view buffer contents, press C-c to return to the save operation
C-x K Delete current buffer
Kill-some-buffers List all buffers, one by one asking if you want to delete
Rename-buffer Modify Buffer Name
C-x c-v Replace the contents of a buffer with the contents of a file

C-x C-q

Buffer read-only/read-write mode switching

C-x 0

Delete Current Window
C-x 1 Delete all Windows outside the current window
C-x 2 The current window is split to top and bottom 2
C-x 3 The current window is divided into about 2
Delete-windows-on Delete all windows on a particular edit buffer
C-x o Switch to the next window
M-n c-x o Perform a switch to the next window operation N Times
C-x ^ Highlight Current Window
C-} Widen the current window horizontally
c-{ Reduce the current window horizontally
Shrink-window Shrinking a window in a vertical direction
C-u Perform the above enlarged or reduced, highlighted commands four times times at a time
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally
c-{ Reduce the current window horizontally

About Emacs Buffers and windows

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.