343 lines
15 KiB
HTML
343 lines
15 KiB
HTML
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||
|
<HTML>
|
||
|
<HEAD>
|
||
|
<META NAME="GENERATOR" CONTENT="SGML-Tools 1.0.9">
|
||
|
<TITLE>Emacs Beginner's HOWTO: Running Emacs </TITLE>
|
||
|
<LINK HREF="Emacs-Beginner-HOWTO-3.html" REL=next>
|
||
|
<LINK HREF="Emacs-Beginner-HOWTO-1.html" REL=previous>
|
||
|
<LINK HREF="Emacs-Beginner-HOWTO.html#toc2" REL=contents>
|
||
|
</HEAD>
|
||
|
<BODY>
|
||
|
<A HREF="Emacs-Beginner-HOWTO-3.html">Next</A>
|
||
|
<A HREF="Emacs-Beginner-HOWTO-1.html">Previous</A>
|
||
|
<A HREF="Emacs-Beginner-HOWTO.html#toc2">Contents</A>
|
||
|
<HR>
|
||
|
<H2><A NAME="running_emacs"></A> <A NAME="s2">2. Running Emacs </A></H2>
|
||
|
|
||
|
<H2><A NAME="ss2.1">2.1 Starting & Quitting Emacs</A>
|
||
|
</H2>
|
||
|
|
||
|
<P>As 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 <CODE>emacs</CODE> and hit enter. Emacs should start up. If
|
||
|
not, it is either not installed or not in your path.
|
||
|
<P>
|
||
|
<P>Once you've seen Emacs, you need to know how to exit. The
|
||
|
keystrokes for leaving Emacs are <CODE>C-x C-c</CODE>. The <CODE>C-x</CODE>
|
||
|
notation means hold down the <CODE>Ctrl</CODE> key and press
|
||
|
<CODE>x</CODE>. In this case, you'll then need to hold down <CODE>Ctrl</CODE>
|
||
|
and press <CODE>c</CODE> to finish the task.
|
||
|
<P>
|
||
|
<P>The keystrokes used in Emacs will likely seem odd, foreign, and
|
||
|
maybe even uncomfortable to you at first--especially if you're a
|
||
|
<CODE>vi</CODE> user. Unlike <CODE>vi</CODE>, Emacs doesn't have separate
|
||
|
modes for editing text and issuing commands.
|
||
|
<P>
|
||
|
<P>To re-cap: <CODE>emacs</CODE> will start Emacs. <CODE>C-x C-c</CODE> will
|
||
|
exit Emacs.
|
||
|
<P>
|
||
|
<H3>What you'll see</H3>
|
||
|
|
||
|
<P>When 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.
|
||
|
<P>
|
||
|
<P>It will look something like this ASCII sketch:
|
||
|
<P>
|
||
|
<PRE>
|
||
|
+----------------------------------------------------------------------+
|
||
|
|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. |
|
||
|
+----------------------------------------------------------------------+
|
||
|
</PRE>
|
||
|
<P>
|
||
|
<P><B>NOTE:</B> 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 ``<CODE>...</CODE>'' instead. The
|
||
|
welcome message simply identifies the exact version of Emacs you are
|
||
|
using as well as pointing you to the on-line help and related items.
|
||
|
<P>
|
||
|
<H3>The Menu Bar</H3>
|
||
|
|
||
|
<P>The 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.
|
||
|
<P>
|
||
|
<H3>The Status Bar and Mini-buffer</H3>
|
||
|
|
||
|
<P>Of 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.
|
||
|
<P>
|
||
|
<P>The bottommost line is called the <B>mini-buffer</B>. 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.
|
||
|
<P>
|
||
|
<P>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.
|
||
|
<P>
|
||
|
<H2><A NAME="ss2.2">2.2 Some Terminology</A>
|
||
|
</H2>
|
||
|
|
||
|
<P>This section covers the most basic of Emacs terminology that you'll
|
||
|
encounter when using and reading about Emacs.
|
||
|
<P>
|
||
|
<H3>Buffers & Files</H3>
|
||
|
|
||
|
<P>Unlike 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 <B>buffer</B> 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.
|
||
|
<P>
|
||
|
<P>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.
|
||
|
<P>
|
||
|
<H3>Point & Region</H3>
|
||
|
|
||
|
<P>In Emacs lingo, you'll often hear or see references to the
|
||
|
<B>point</B>. 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
|
||
|
<EM>between characters</EM> 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'.
|
||
|
<P>
|
||
|
<P>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
|
||
|
<B>region</B>.
|
||
|
<P>
|
||
|
<H3>Windows</H3>
|
||
|
|
||
|
<P>Okay, 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.
|
||
|
<P>
|
||
|
<P>A <B>window</B> 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.
|
||
|
<P>
|
||
|
<P>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 <B>frames</B> in Emacs lingo. Read on.
|
||
|
<P>
|
||
|
<H3>Frames</H3>
|
||
|
|
||
|
<P>In Emacs, a <B>frame</B> 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.
|
||
|
<P>
|
||
|
<H2><A NAME="ss2.3">2.3 Keyboard Basics</A>
|
||
|
</H2>
|
||
|
|
||
|
<P>This 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.
|
||
|
<P>
|
||
|
<P>If you're a <CODE>vi</CODE> user, the notion of using the <CODE>k, j, l,
|
||
|
h</CODE> keys to move up a line, down a line, forward by a character,
|
||
|
and backward by a character probably took some getting used to. In
|
||
|
fact, it might have taken you a few hours or even weeks of practice
|
||
|
before you could comfortably navigate a file using the various key
|
||
|
combinations available in <CODE>vi</CODE>.
|
||
|
<P>
|
||
|
<P>Emacs is no different. There are different keystrokes and commands
|
||
|
to learn. Just like <CODE>vi</CODE>, you only need to master the basics to
|
||
|
get a lot of work done. Then, as time goes on, you can slowly expand
|
||
|
your knowledge and find faster ways of doing things.
|
||
|
<P>
|
||
|
<H3>Command Keys (Meta, Esc, Control, and Alt)</H3>
|
||
|
|
||
|
<P>As you'll soon learn, Emacs makes heavy use of multi-key
|
||
|
combinations. Because it is not a modal editor like <CODE>vi</CODE>, you
|
||
|
don't have to think about being in ``command mode'' or ``editing
|
||
|
mode'' before you can try to move the cursor or execute a
|
||
|
command. Instead, you just press the right combination of keys and
|
||
|
Emacs does as told (usually).
|
||
|
<P>
|
||
|
<P>The keys that Emacs makes the most use of are usually abbreviated in
|
||
|
the documentation as <CODE>C</CODE> (for Control or Ctrl) and <CODE>M</CODE>
|
||
|
for (Meta). While most modern PC keyboards have one or more keys
|
||
|
labeled <CODE>Ctrl</CODE> few have one labeled <CODE>Meta</CODE>. You'll want
|
||
|
to mentally substitute either <CODE>Esc</CODE> or <CODE>Alt</CODE> for the Meta
|
||
|
key. In most standard configurations, both Esc and Alt do essentially
|
||
|
the same thing.
|
||
|
<P>
|
||
|
<P>So when you see a reference in any Emacs related documentation to
|
||
|
<CODE>C-x f</CODE> it means ``press control-x and then f.'' And if you see
|
||
|
a reference to something like <CODE>M-x shell</CODE> is means ``press
|
||
|
alt-x and type the word shell''.
|
||
|
<P>
|
||
|
<P>A very useful command for beginners is <CODE>M-x apropos</CODE> or
|
||
|
<CODE>C-h a</CODE>. apropos will search the Emacs on-line documentation
|
||
|
for all functions and search for the regular expression you type. This
|
||
|
is a great way to discover all commands related to frames. Simply
|
||
|
<CODE>C-h a</CODE> and then <CODE>frame</CODE>.
|
||
|
<P>
|
||
|
<H3>Moving Around in a Buffer</H3>
|
||
|
|
||
|
<P>Now that you know what all those fancy abbreviations mean, here's a
|
||
|
list of the most common keystrokes for moving within a buffer:
|
||
|
<P>
|
||
|
<PRE>
|
||
|
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
|
||
|
-----------------------------------
|
||
|
</PRE>
|
||
|
<P>
|
||
|
<P>And, as you might expect, the cursor keys (or arrow keys) usually
|
||
|
work just as you'd expect. Your <CODE>Backspace</CODE> may not. That's
|
||
|
another story. <CODE>:-(</CODE>
|
||
|
<P>
|
||
|
<H3>Essential Commands</H3>
|
||
|
|
||
|
<P>Okay, now that you know how to move around within a buffer what
|
||
|
about opening and saving files? Search? Here are some basic commands.
|
||
|
<P>
|
||
|
<P>Before we jump straight to those commands, I need to briefly point
|
||
|
out how this works.
|
||
|
<P>
|
||
|
<P>All ``command keystrokes'' in Emacs (those that are <CODE>M-x
|
||
|
something</CODE> or <CODE>C-something</CODE>) are actually just shortcuts to
|
||
|
functions which are part of Emacs. You can call any of those functions
|
||
|
by typing <CODE>M-x function-name</CODE> and hitting <CODE>Enter</CODE>. You
|
||
|
can also use the keyboard shortcut for that function (if it has one).
|
||
|
<P>
|
||
|
<P>For example, the Emacs function which saves a buffer to disk is
|
||
|
called <CODE>save-buffer</CODE>. By default it is also bound to <CODE>C-x
|
||
|
C-s</CODE>. So, you can either use they shortcut to save the current
|
||
|
buffer, or you could type <CODE>M-x save-buffer</CODE> and achieve the
|
||
|
exact same result.
|
||
|
<P>
|
||
|
<P>All of the most common functions have keyboard shortcuts by
|
||
|
default. Some of them are listed below.
|
||
|
<P>
|
||
|
<PRE>
|
||
|
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.
|
||
|
-------------------------------------------------------------------
|
||
|
</PRE>
|
||
|
<P>
|
||
|
<P>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 <CODE>:</CODE> commands in <CODE>vi</CODE> or most
|
||
|
commands that you'd use within your favorite Unix shell.
|
||
|
<P>
|
||
|
<P>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.
|
||
|
<P>
|
||
|
<H3>Tab Completion</H3>
|
||
|
|
||
|
<P>Like many popular Unix shells (bash, csh, tcsh, ...) Emacs offers
|
||
|
command completion via the <CODE>Tab</CODE> key. In fact, the command
|
||
|
completion in bash was modeled after that in Emacs, so if you use that
|
||
|
feature in bash you'll be right at home.
|
||
|
<P>
|
||
|
<P>As an example, try <CODE>M-x search</CODE> and then hit
|
||
|
<CODE>Tab</CODE>. Emacs will append a hyphen to indicate that there are
|
||
|
several possible completions but they all have a hyphen as the next
|
||
|
character. Hit <CODE>Tab</CODE> once more and Emacs will display a list of
|
||
|
the possible matches for you to choose from. Notice that it does so in
|
||
|
a <EM>new window</EM>. It temporarily splits your display into two
|
||
|
windows: one which contains the buffer you were editing and the other
|
||
|
contains the list of possible completions for ``search-''. You may hit
|
||
|
<CODE>C-g</CODE> to exit out of the selection process and close the new
|
||
|
window.
|
||
|
<P>
|
||
|
<H2><A NAME="ss2.4">2.4 Tutorial, Help, & Info</A>
|
||
|
</H2>
|
||
|
|
||
|
<P>Emacs 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.
|
||
|
<P>
|
||
|
<P>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 <CODE>C-h
|
||
|
t</CODE>. The tutorial is self-guided and aimed at folks who are just
|
||
|
getting started with Emacs.
|
||
|
<P>
|
||
|
<P>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.
|
||
|
<P>
|
||
|
<P>Finally, to see the volume of documentation available with Emacs,
|
||
|
you should try <CODE>M-x info</CODE> or <CODE>C-h i</CODE> which launches
|
||
|
Info, the Emacs documentation browser.
|
||
|
<P>
|
||
|
<HR>
|
||
|
<A HREF="Emacs-Beginner-HOWTO-3.html">Next</A>
|
||
|
<A HREF="Emacs-Beginner-HOWTO-1.html">Previous</A>
|
||
|
<A HREF="Emacs-Beginner-HOWTO.html#toc2">Contents</A>
|
||
|
</BODY>
|
||
|
</HTML>
|