Chapter 6. Editing Files with Emacs

GNU/Emacs is a large, complex text editor. It has a very large number of custom modes for editing specific types of files. For example, when you edit a file of Ada source code, emacs goes into Ada mode, with proper indenting rules, color highlighting, and hotkeys for Ada. Emacs uses Ctrl and Alt key combinations for commands. In emacs, the Alt key is referred to as the Meta key. (On some systems, the Alt key is not mapped to Meta, and you instead use the Esc key for Meta.) Most key combinations are at least somewhat mnemonic. For example, the end-of-line function is invoked by C-e (which means Ctrl-e, holding down the Ctrl key while pressing e). Emacs is used so widely that some of the better-known key combinations are used in other applications. For example, C-e is also end-of-line in the Netscape html editor, adopted from emacs. Often, if a control-key command invokes some action, then the alt-key combination of the same key moves similarly but more so. For example M-e (i.e., Meta-e, meaning Alt-e) is end-of-sentence.

Important Emacs commands

Table 6-1. Important Emacs Commands:

C-x C-c Exit emacs (prompts for save)
C-g Cancels the current command which is in progress
C-x C-w Writes the current buffer to a new file (save as)
C-h Online help
C-x 1 Hides all emacs windows except the current one
C-x i Insert text from a file at the current location
M-< Move cursor to the beginning of buffer
M-> Move cursor to the end of buffer
M-{ Move cursor to the beginning of paragraph
M-} Move cursor to the end of paragraph
C-a (M-a) Move cursor to beginning of line (sentence)
C-e (M-e) Move cursor to end of line (sentence)
C-k (M-k) Kill (delete) to end of line (sentence)
C-Space Set the mark at the current cursor location
C-w Kill the marked (highlighted) text and copy it to the kill ring buffer
M-w Copy the marked text to the kill ring buffer without deleting it
C-x < Start recording a keyboard macro
C-x ) Finish recording a keyboard macro
C-x e Execute the most recently recorded keyboard macro
C-s Begin interactive search
M-% Interactive search and replace