GNU Emacs
Emacs
Dashboard

19.3 Miscellaneous Buffer Operations

C-x C-q

Toggle read-only status of buffer ( read-only-mode).

C-x x r RET buffer RET

Change the name of the current buffer.

C-x x u

Rename the current buffer by adding ‘ <number>’ to the end.

M-x view-buffer RET buffer RET

Scroll through buffer buffer. See View Mode.

A buffer can be read-only, which means that commands to insert or delete its text are not allowed. (However, other commands, like C-x RET f, can still mark it as modified, see Specifying a Coding System for File Text). The mode line indicates read-only buffers with ‘ %%’ or ‘ %*’ near the left margin. See The Mode Line. Read-only buffers are usually made by subsystems such as Dired and Rmail that have special commands to operate on the text. Visiting a file whose access control says you cannot write it also makes the buffer read-only.

The command C-x C-q ( read-only-mode) makes a read-only buffer writable, and makes a writable buffer read-only. This works by setting the variable buffer-read-only, which has a local value in each buffer and makes the buffer read-only if its value is non- nil. If you change the option view-read-only to a non- nil value, making the buffer read-only with C-x C-q also enables View mode in the buffer (see View Mode).

C-x x r ( rename-buffer changes the name of the current buffer. You specify the new name as a minibuffer argument; there is no default. If you specify a name that is in use for some other buffer, an error happens and no renaming is done.

C-x x u ( rename-uniquely) renames the current buffer to a similar name with a numeric suffix added to make it both different and unique. This command does not need an argument. It is useful for creating multiple shell buffers: if you rename the *shell* buffer, then do M-x shell again, it makes a new shell buffer named *shell*; meanwhile, the old shell buffer continues to exist under its new name. This method is also good for mail buffers, compilation buffers, and most Emacs features that create special buffers with particular names. (With some of these features, such as M-x compile, M-x grep, you need to switch to some other buffer before using the command again, otherwise it will reuse the current buffer despite the name change.)

The commands M-x append-to-buffer and C-x x i ( insert-buffer) can also be used to copy text from one buffer to another. See Accumulating Text.