11. Emacs Buffer Navigation

In Emacs, a "buffer" is a temporary workspace where you can edit text. When you open a file, Emacs loads its contents into a buffer. You can also have buffers that don't correspond to a file, such as the *scratch* buffer. Efficiently managing these buffers is key to a smooth workflow. Mastering emacs navigation between buffers will significantly speed up your editing process.

Switching Between Buffers

To move between different open buffers, you can use several commands. The primary command to emacs switch buffer will prompt you for the name of the buffer you want to open.

C-x b - Switch to another buffer by name
C-x right arrow - Cycle to the next buffer
C-x left arrow - Cycle to the previous buffer

Managing Buffer Windows

Emacs allows you to view multiple buffers at once by splitting your screen (or "frame") into different windows.

C-x 2 - Split the current window vertically

This command creates two windows, one above the other, allowing you to see two buffers simultaneously. To move your cursor between these windows, use:

C-x o - Move to the other window

When you are finished with a split-screen view and want to return to a single window, you can use the following command. This makes the current window the only one on the screen.

C-x 1 - Close all other windows

Closing a Buffer

When you are done working with a file or a temporary buffer, you can close it to keep your workspace tidy.

C-x k - Kill (close) the current buffer

If you have ever used a terminal multiplexer like screen or tmux, you will find that these buffer management commands feel very familiar.

Sign in to save your learning progress

Sign in

Exercises

To solidify your understanding of buffer and text file manipulation, try these hands-on labs. They will help you apply these concepts in real-world scenarios.

  1. Edit Text Files in Linux with Vim and Nano - Practice creating, editing, saving, and navigating text within the Vim and Nano editors, which are crucial for working with buffers.
  2. Linux cat Command: File Concatenating - Learn to view, concatenate, and manipulate text files, directly applying to how you might interact with buffer content.
  3. Viewing Log and Configuration Files in Linux - Practice using commands like cat, more, and less to efficiently view and navigate text files, simulating real-world scenarios of examining buffer-like content.

These labs will help you build confidence with text file and buffer manipulation in Linux.

Quiz

How do you kill a buffer? Please answer using the exact keybinding in English, paying attention to case.