Editing Files with Emacs¶
If you’re going to use Linux, there simply is no avoiding emacs. You’ve probably heard of it, the powerful text editor that provokes wars between its devoted fans and fans of its more ancient but still omnipresent competitor vi. To those of us migrating to Linux from a more graphically oriented environment, both programs seem alien. You might think you can escape by using some other program, but you can’t escape because every program you pick up tries to imitate emacs in some way.
Getting to know emacs may be a necessity, but it’s no picnic for immigrants from other operating systems. We know that emacs is “powerful”, and we would like to access all that power, but it’s so hard just to get started editing a file! As a beginner, I started up emacs thinking it would be like any word processor. Fifteen minutes later I was rebooting my computer, having been unable to figure out how to do anything — including exit the program!
Don’t give up! Things have gotten a lot easier since my first days using Linux. These days, Emacs is pretty easy to figure out. If you start it up from your GUI, you’ll get a GUI version with full mouse support, and you can click to explore as with most GUI programs. Also, when started without giving it a file to edit, Emacs will present you with a nice tutorial that walks you through how to use the program.
Understanding Emacs Terminology¶
Ordinarily I would not bother going over simple terminology used in a program’s documentation, but this is necessary with Emacs because it uses a few terms that are not “normal”, or not used in normal ways.
First, there is a shorthand used in Emacs documentation (and most other Linux
documentation) for describing key combinations. A capital “C” followed by a dash
C-) means to hold the
Control key down while pressing the following
C-m means to hold the
Control key while pressing
capital “M” followed by a dash (
M-) means to hold down the
PC’s don’t have a Meta key, so usually this means the
Alt key. (It may be
only the left Alt key, or only the right, or both, depending on your
You will find in the Emacs documentation many references to buffers (and even a menu by that name). A buffer is roughly what we would call an open file, although some buffers contain information that is not a file. And according to the Emacs documentation, you don’t open a file, you visit one. (The file menu disagrees.) So a buffer contains a file that you are currently visiting.
Emacs Quick Reference¶
- Exit Emacs. If there are unsaved files open, Emacs will ask you to save them.
- Suspend Emacs. If used under the X window system, this command will shrink the Emacs frame to an icon.
- Find File. Visit or Open a file.
- Save the current buffer.
- Save All. Offers to save all modified buffers.
- Save As (Write). Save the current buffer under a new name.
- Close file. Offers to save the current buffer if modified, then kills it.
- Cut selected text to the kill-ring.
- Copy selected text to the kill-ring.
- “Yank” or Paste the kill-ring contents at the cursor.
- Delete the current selection (without placing in kill-ring)
- Undo one batch of changes (usually, one command’s worth).
- Move the cursor to the beginning of the line
- Move the cursor to the end of the line
- Move the cursor backward one word
- Move the cursor forward one word
- Move the cursor to the beginning of the buffer
- Move the cursor to the end of the buffer