Linux Mall - The Linux SuperStore!
Linux books, Linux CDs, Linux toys, you name it, they have it!

W W W . L I N U X D O T . O R G

Newbie's Linux Manual
Emacs Tutorial #1: Basic Editing
] [ Download*] [ Previous] [ Next] Home] [ Contents] [ Download*] [ Previous] [ Next] Homepage| The Last 5 Days| The Daily Linux News| The Linux Bits| Newbie's Linux Manual
The Best Linux Sites| Linux Book Reviews| A Windows Vendetta?
Diary of a Linux Newbie| Diary of an Open Source Newbie
The Linux Forum| Just For Fun Amazon - The World's Biggest Bookstore!
4.7 million books, CDs, videos, and DVDs available to buy! Webmaster| Manual's Copyright Terms
[
* In Linux enter: unzip nlm.zip
In Emacs:
  • You edit "buffers", not "documents". Same thing, different name.

  • Ctrl+x is represented as C-x.

  • M-w means "Meta key"+w. On your PC keyboard the Meta key is your Alt key. So M-w means Alt+w.

To start Emacs, enter:

emacs filename

If the file exists then Emacs will open it for editing. Otherwise Emacs will begin with a new buffer (document) that will default to being saved as that filename.

Note:

Emacs can be started from X or from the console, the choice is yours. The only real drawback of running Emacs from the console is that menus are activated using the F10 key and they're really ugly.

What Those Key Combo Mean
C-x C-s means whilst holding down the Ctrl key, tap the x key, and then the s key.

C-x b means press Ctrl+x, release both keys, and then press b.

Moving
Cursor keys

As you would expect.

[PageUp] "         "
[PageDn] "         "
M-<

Move to start of buffer (document).

M->

Move to end of buffer (document).

C-l (el)

Scroll display so that current line is in the middle.

M-f

Move forward a word.

M-b

Move back a word.

C-a

Move to start of line.

C-e

Move to end of line.

M-a

Move to start of sentence. *

M-e

Move to end of sentence. *

* Only works if 2 spaces follow/precede sentence.

Cut (Kill), Copy, & Paste (Yank)

To Cut or Copy text you need to set a "Mark" and a "Point". Move the cursor to a particular position and press C-Space to set the Mark. The Point is just the position of the cursor so move it one space beyond where you want to Cut or Copy.

   "region"
<------------>
M             P

M=Mark   (Set with C-space)
P=Point  (Cursor position)
C-w

Cut (Emacs terminology: "kill the region").

C-k

This Cuts but you don't set a Mark to use it. Move the cursor somewhere, and whilst holding down the Ctrl key, tap away at the k key. Now move somewhere else and press Ctrl+y. Note that when you use repitition (e.g. C-u 5 C-k) you don't need to take the cutting of the newline characters into account. The best way of understanding this command is to play about with it for a few minutes.

M-w Copy.
C-y

Paste (Emacs terminology: "yank text into buffer").

M-y

After you paste some text you can replace with text you've previously cut or copied it by cycling backwards through all the text you've cut or copied.

Save, Open (Find), & Exit

When you first save a modified document in Emacs, the original file will be saved as ~filename in case you ever want to revert back to it. Emacs will also autosave your document in case of power loss, a crash etc, giving the autosaved file the name #filename# and delete the file every time you save the document. To recover a file, open the normal file (not the autosaved file) and enter: M-x recover file.

C-x C-s

Save current buffer to file.

C-x C-w

Save current buffer as...

C-x s

If you had many buffers open, it would be annoying if you had to swap to each before saving them. This will ask in turn, ask which you want to save.

C-x C-f

Open (Emacs Terminology: "find") a file into a new buffer (filename completion available with Tab key). By opening a file that doesn't exist, you start a new named document. And by opening a file that's already open you switch to it.

C-x d

Browse your Linux filesystem. Either press Enter or the middle mouse button (both together on a 2 button mouse) to open a file or move to another directory.

C-x i

Insert contents of another file at cursor.

C-x C-c

Exit Emacs. (Note: In console mode you could also suspend Emacs with Ctrl+z, do something else, then bring it back with: fg (In X, Ctrl+z will just minimise the window.))

Search & Replace
C-s

Enter isearch mode. Type the word, word completion will take place and Emacs will jump to the next word that starts with what you've entered. Press C-s for next occurence. (Document wrap takes place.)

C-r

Same as C-s but search occurs in reverse direction.

M-%

Replace...

Buffers/Windows
C-x 1

Maximise current buffer.

C-x 2

Switch current buffer into 2. (Use: C-x o ("o" for "other") to switch from top to bottom.)

C-x 5 2

Open current buffer in new frame.

C-x b

Switch to another buffer.

C-x C-b

List buffers.

C-x k

Kill a buffer. Press Enter to kill the current buffer or enter the name of another buffer to kill. The name of a buffer is the filename minus the path.

Undo & Redo
C-x u

Undo (infinite).

C-_ "         "
Help
C-h k key combo

Display documentation for key combo.

C-h ?

Display list of types of help and how to access them.

Repitition

Vi has it and Emacs has it. It's one of the things that seperates Unix/Linux editors from the Windows crop. To repeat a command in Emacs press Ctrl+u, followed by the amount of times to repeat an operation, and finally the operation itself. Here's some examples:

C-u 30 =

Insert 30 "="s at cursor.

C-u 10 [Down Cursor]

Move cursor down 10 lines.

C-u 3 C-x u

Undo 3 times.

Miscellaneous
C-g

Cancel half way through just about anything. Very handy.

[
* In Linux enter: unzip nlm.zip
© MM Linuxdot.org |