1.6. Emacs Commands
You're about to start learning some Emacs commands, so let's discuss them a bit first. How do you give commands? Each command has a formal name, which (if you're fastidious) is the
Emacs ties a command name to a short sequence of keystrokes. This tying of commands to keystrokes is known as
binding
. Even things you don't normally think about as commands, such as inserting the
The authors of Emacs try to bind the most frequently used commands to the key sequences that are the
You can define your own key bindings, too, and you should do so if you find yourself using the long form of a command all the time. More on this topic in Chapter 10. You can also access common commands through menus, but for maximum productivity, we recommend you learn the keystrokes, often given in parentheses following the menu option. |
1.7. Opening a File
You can
The paper icon on the toolbar also runs this command. In some applications, a similar icon simply creates a new, unnamed file (e.g., Document1 in Word). Emacs expects you to provide a filename, as we'll see in a moment.
To press C-x C-f , hold down Ctrl , press x and then press f . Now release Ctrl . After you press C-x C-f , Emacs uses the minibuffer to ask you for the filename. Whenever Emacs wants input from you, it puts the cursor in the minibuffer. When you're done typing in the minibuffer, press Enter .
What if you try to read the same file twice? Instead of creating a new buffer, Emacs just moves you to the buffer the file is in. You can also open a file in Emacs by dragging and dropping it on an Emacs window or on the Emacs icon. Now is a good time to try typing if you haven't already done so. You may find yourself wanting to learn more about cursor movement and editing; that's fine. Feel free to skim the rest of this chapter and go on to Chapter 2. We recommend that you read the sections on saving files and exiting Emacs. There's also a table of commands at the end of this chapter for future reference. If you'd like to learn more about working with files as well as some shortcuts, stay with us through the rest of the chapter. 1.7.1 If You Read the Wrong File
If you happen to read the wrong file, an easy way to get the right file is by typing
C-x C-v
(for
find-alternate-file
). This command means "Read a different file instead of the one I just read." After typing
C-x C-v
, Emacs puts the name of the current file in the minibuffer; you can then correct a typo or the
1.7.2 Letting Emacs Fill in the Blanks
Emacs has a very helpful feature known as completion. If you want an existing file, you need only type the first few
{% if main.adsdop %}{% include 'adsenceinline.tpl' %}{% endif %}
If more than one file starts with
di
, Emacs displays a window with various files that start with that string. You select one by typing a few more
Completion also works for long command
1.7.3 Inserting and Appending FilesIf you want to insert one file into another, you simply move to the appropriate location in the file and type C-x i . (Yes, we know, we haven't told you how to move around in a file yet. Use the arrow keys for now and we'll teach you the "real" Emacs cursor movement commands in Chapter 2.) To append a file, move to the end of the file ( M-> ) and type C-x i . As with C-x C-f , Emacs prompts you for the filename in the minibuffer. 1.7.4 How Emacs Chooses a Default DirectoryWhen you use any command that asks for a filename (such as C-x C-f ), Emacs displays a default directory in the minibuffer and asks you to type the rest of the filename. How does Emacs choose the default directory? The default directory is taken from the buffer that the cursor is currently in. If you are editing a file in your home directory when you type C-x C-f , Emacs assumes you want to edit another file in your home directory. If you are editing the file /sources/macros/html.macs then Emacs makes the default directory /sources/macros . If you want to find a file in another directory, edit the default directory that Emacs displays. |