s i s t e m a o p e r a c i o n a l m a g n u x l i n u x | ~/ · documentação · suporte · sobre |
Next
Previous
Contents
2. Running Emacs2.1 Starting & Quitting EmacsAs a new user, you'll probably want to launch Emacs just to mess
around and try it out. Once you're into Emacs and want to exit,
however, you may not be able to figure out what to do. So if you've
never used Emacs before, give it a shot right now. At your shell
prompt, type
Once you've seen Emacs, you need to know how to exit. The
keystrokes for leaving Emacs are
The keystrokes used in Emacs will likely seem odd, foreign, and
maybe even uncomfortable to you at first--especially if you're a
To re-cap:
What you'll seeWhen Emacs starts up it will consume a whole X window (or screen if you're running on a console instead of in the X Window System). You'll see a menu across the top, some text in the main part of the screen, and a couple of lines at the bottom.
It will look something like this ASCII sketch:
+----------------------------------------------------------------------+ |Buffers Files Tools Edit Search Mule Help | | | |Welcome to GNU Emacs, one component of a Linux-based GNU system. | | | | | | | | ... | | | |---1:---F1 *scratch* (Lisp Interaction)--L1--All-------------| |For information about the GNU Project and its goals, type C-h C-p. | +----------------------------------------------------------------------+
NOTE: Emacs will usually fill the entire
screen/window. I've shrunk the above example to save space here. You
will also see a welcome message in Emacs when you first start it. I
omitted that as well and substituted ``
The Menu BarThe topmost line of the Emacs interface is a menu. If you're running X, you'll recognize them as traditional pull-down menus that you can access using your mouse. Otherwise you'll need to use keyboard shortcuts (not covered here) for accessing the menus.
The Status Bar and Mini-bufferOf the last two lines in the Emacs interface, the topmost one is essentially a status bar. It contains information about the buffer you're working in, which mode Emacs is in, and various other things. For now, just realize that it's there.
The bottommost line is called the mini-buffer. It is separated from the main buffer by the status bar we just discussed. You can think of the mini-buffer as the Emacs ``command-line''. It is where commands that you give Emacs appear and it is where status messages are printed in response to things you do.
You'll find that what I've called the status bar is usually referred to as the mode line in Emacs related documentation. It is where Emacs displays information about the current modes(s) you may be using as well as things like the current date and time, line number, file size, and almost anything else you might want to see there.
2.2 Some TerminologyThis section covers the most basic of Emacs terminology that you'll encounter when using and reading about Emacs.
Buffers & FilesUnlike some editors, when you open a file in Emacs it does not stay ``open'' the entire time you're working with it. Instead, Emacs reads the file into a buffer in memory. While you're editing the buffer and working with the data nothing is changed on disk. Only when you actually save the buffer does the file on disk get updated. There are advantages and disadvantages to this approach but it is only important that you understand that it works this way.
As a consequence, you will see the term ``buffer'' used in Emacs documentation, modes, packages, and so on. Just realize that buffer means ``a copy of the file that is currently in memory.'' Oh, it's worth pointing out that a buffer doesn't always have to refer to a specific file on disk. Often times Emacs will create buffers as the result of commands you run. Such buffers may contain the result of the command, a list of selections to pick from, and so on.
Point & RegionIn Emacs lingo, you'll often hear or see references to the point. In general terms the point is the cursor. The actual distinction between the point and cursor probably isn't important when you're first starting out with Emacs. But if you are curious, think about it this way. The cursor is the visual representation of the point. The cursor is always ``on'' a particular character position in the current buffer. The point, on the other hand, lives in the space between characters on in the buffer. So you might say that if the cursor is on the letter `h' in the word ``the'' then the point is between the `t' and the `h'.
Like many modern editors, Emacs allows to perform operations (indent, spell-check, reformat, cut, copy, paste, ...) on a section of the current buffer. You can highlight (or ``mark'') a block of text using the keyboard or mouse and then perform operations on just the selected block of text. In Emacs, that block of text is called a region.
WindowsOkay, this will be a bit confusing to anyone who has ever used a GUI interface before. Just remember that Emacs was developed long before GUI interfaces and window managers were popular.
A window in Emacs is an area of the screen in which a buffer is displayed. When Emacs is first started, you have one window on your screen. Some Emacs functions (such as the help and documentation) often [temporarily] open up additional windows in your Emacs screen.
Emacs windows have nothing to do with X windows in the GUI sense. You can open up additional X windows to display Emacs buffers, maybe to compare two files side by side. Those new X windows are referred to as frames in Emacs lingo. Read on.
FramesIn Emacs, a frame is a separate X window in which an Emacs buffer is displayed. But both are part of the same Emacs session. The behavior is somewhat (but not too much) like what happens if you hit Alt+N in Netscape Navigator.
2.3 Keyboard BasicsThis section covers the basics of keyboarding for Emacs. Like every powerful editor, everything that you can do with Emacs is just a few keystrokes away.
If you're a
Emacs is no different. There are different keystrokes and commands
to learn. Just like
Command Keys (Meta, Esc, Control, and Alt)As you'll soon learn, Emacs makes heavy use of multi-key
combinations. Because it is not a modal editor like
The keys that Emacs makes the most use of are usually abbreviated in
the documentation as
So when you see a reference in any Emacs related documentation to
A very useful command for beginners is
Moving Around in a BufferNow that you know what all those fancy abbreviations mean, here's a list of the most common keystrokes for moving within a buffer:
Keystrokes Action ----------------------------------- C-p Up one line C-n Down one line C-f Forward one character C-b Backward one character C-a Beginning of line C-e End of line C-v Down one page M-v Up one page M-f Forward one word M-b Backward one word M-< Beginning of buffer M-> End of buffer C-g Quit current operation -----------------------------------
And, as you might expect, the cursor keys (or arrow keys) usually
work just as you'd expect. Your
Essential CommandsOkay, now that you know how to move around within a buffer what about opening and saving files? Search? Here are some basic commands.
Before we jump straight to those commands, I need to briefly point out how this works.
All ``command keystrokes'' in Emacs (those that are
For example, the Emacs function which saves a buffer to disk is
called
All of the most common functions have keyboard shortcuts by default. Some of them are listed below.
Keystrokes Function Description ------------------------------------------------------------------- C-x C-s save-buffer Save the current buffer to disk C-x u undo Undo the last operation C-x C-f find-file Open a file from disk C-s isearch-forward Search forward for a string C-r isearch-backward Search backward for a string replace-string Search & replace for a string replace-regexp Search & replace using regexp C-h t help-with-tutorial Use the interactive tutorial C-h f describe-function Display help for a function C-h v describe-variable Display help for a variable C-h x describe-key Display what a key sequence does C-h a apropos Search help for string/regexp C-h F view-emacs-FAQ Display the Emacs FAQ C-h i info Read the Emacs documentation C-x r m bookmark-set Set a bookmark. Useful in searches C-x r b bookmark-jump Jump to a bookmark. -------------------------------------------------------------------
As you try many of those functions, you'll notice that many will
prompt you for input. They will always to do in the mini-buffer. This
is similar to using the
Emacs has literally hundreds of built-in functions available. The list above is a tiny sample that represents those that I use regularly. See the on-line help for a more complete listing of the available functions and more complete documentation on those I mentioned above.
Tab CompletionLike many popular Unix shells (bash, csh, tcsh, ...) Emacs offers
command completion via the
As an example, try
2.4 Tutorial, Help, & InfoEmacs comes with an on-line tutorial which walks you through the basic editing features and functions that everyone should know. It also explains how to use the other help features in Emacs.
I highly recommend that you spend some time going through the
tutorial if you plan on making a serious effort to learn Emacs. As
shown in the table above, you can enter the tutorial via
If you are running Emacs in X, you will see that the rightmost menu on the menu bar is labeled Help. As you explore the Help menu notice that some items have keyboard shortcuts and those are listed right in the menu.
Finally, to see the volume of documentation available with Emacs,
you should try
Next Previous Contents |