The emacs Editor


The emacs Editor

Most emacs lovers hate vi and vice versa. Why such rivalry? Well, I hope that you have yet to be tainted by someone else's opinions. I hope that you can make a decision on your own from this Unix lesson alone. Take a look at both and form your own opinion on what can be most useful to you and learn how to use that tool as in-depth as you can. In this lesson, we will look at the emacs editor.

You will find that the biggest difference between the emacs editor and the vi editor is the actual footprint of the programs. Whereas the vi editor is a lightweight, highly functional tool, the emacs editor is a dense, unbelievably functional tool. Don't worry, both will serve just about any need you can dream of; most times the selection is preference. Very few get to levels where they know so much about both that they can rattle off verbatim all the differences and why you would want to use one over the other in specific circumstances. The easiest way to make a decision if you are completely new to Unix is to consider again that the vi editor is functional and very lightweight. The vi editor doesn't eat up a lot of your computer's hardware resources like memory and CPU cycles. The emacs editor, however, can be resource intensive and actually tax your system, making it perform slower if too many resources are used. This is because emacs contains a great many things such as an email client, a programming language, and many other features.

In a more technical light, emacs is by far more functional than vi, but again, it all depends on what you are looking for. For the price of functionally, you pay the cost of resource consumption. Life is a give and take, so is Unix running on your workstation's hardware. When we covered the vi editor, we covered its mode. When using emacs, you are always in insert mode. Control (Ctrl key) functions are handled by using Ctrl key sequences instead of a separate mode. We will cover these momentarily. Now that you understand the differences when using emacs and how it operates, let's take a look at how to use the editor:

1.

Choose a file you would like to open and edit.

2.

Issue the emacs command as emacs <filename>.

That's it; it's that easy to do. Once opened, the emacs editor is very similar to the vi editor in that you will manipulate the file's contents, save it, and so on.

Create Files with Ease Using emacs Too! Just like the vi editor, you can open the emacs editor without specifying a file you want to edit; this will then create a new file for you.


Once emacs opens, you will see many ways to get help. Although you can explore on your own, it's suggested you know some basic navigation first; emacs is just as tricky as vi is to get around and takes a little practice first.

Know Your Syntax In the following list, whenever you see Ctrl+ preceding a character, it means that you need to hold down the Control (Ctrl) key and type that character.


Learning and using the emacs editor can be difficult, but here are some tips to help you navigate it and learn it:

  • As mentioned earlier, the emacs editor doesn't have a separate mode for entering commands. There is only one mode and you use the control keys to move to what would be considered another mode. You are always either typing a command or typing textno switching modes between them like the vi editor. To type text, you just need to type it; if you need to enter a command, you can use the control key to do this, usually seen as Ctrl+option.

  • You can position the cursor keys in emacs by using the arrow-key keypad in most every version of emacs and terminal combination. This is handy if you are new to learning how to get around emacs. The emacs editor is easy to use once you master the keyboard shortcuts, just like the vi editor. If the arrow keys don't work, you can also position the cursor by using Ctrl+f to move forward, Ctrl+b to move backwards, Ctrl+p to move to the previous line, and Ctrl+n to move to the next line.

  • You can delete everything from the cursor to the end of the current line by pressing Ctrl+k.

  • Ctrl+g is the emacs "quit what you're doing" command. If you've started typing a command and change your mind, then use Ctrl+g.

  • If you use Ctrl+k to delete a line or lines, you can press Ctrl+y to yank them back again.

  • To save the file you're currently editing, press Ctrl+x Ctrl+s.

  • To save the file to a new filename, press Ctrl+x Ctrl+w <filename>Return.

  • To exit emacs press Ctrl+x Ctrl+c. If emacs asks you about unsaved buffers or saving your work, you can select Yes to the "quit anyway?" question and to save your work.

Beyond the set of Ctrl+ commands that you can use within the emacs editor, the Escape key can also add more functionality if needed. These commands are usually known as emacs meta commands for historical reasons.

Although they're too complicated and too specific to cover in this book, access to many of the interesting emacs meta commands is accomplished by pressing Esc x, and then typing a command of some sort, such as info. The editor will then give you a list of all commands with similar names for you to choose from. You can see that you will find what you need from the list for most situations.

Use the emacs Tutorial If someone offered you a free pot of gold, would you take it? Of course, but what about if they offered you free help on emacs? Yeah, I know, you would pass on it. What fun is there in that?

Although not the most fun, you can take the emacs tutorial to help get a jump on learning it.

To enter the emacs tutorial, all you need to do is start emacs, and press Ctrl+hi (hold the Ctrl key down, press h, release the Ctrl key, and press i). If you type a ? after the Ctrl+h instead of the i you'll see that there's actually a whole world of alternatives to the i; these alternatives give you a large range of different types of helpful information.


Now that you have learned how to edit the files at the shell prompt, let's dive into the GUI and learn how to edit files in KDE.



    SAMS Teach Yourself Unix in 10 Minutes
    Sams Teach Yourself Unix in 10 Minutes (2nd Edition)
    ISBN: 0672327643
    EAN: 2147483647
    Year: 2005
    Pages: 170

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net