[Home] [Credit Search] [Category Browser] [Staff Roll Call] | The LINUX.COM Article Archive |
Originally Published: Monday, 11 September 2000 | Author: Jim Jones |
Published to: learn_articles_firststep/General | Page: 1/1 - [Printable] |
Easing Into Editors: emacs
We are going to be discussing the emacs editor. While we learned that the vim editor is primarily concerned with unadorned text files, the emacs editor is capable of a lot more than simple text file editing. Emacs can do virtually anything that you would want to do on a computer without having launch a separate program (I am sure that someone has even customized a "butter your toast" meta-function). It is that powerful! It can check, display, and manage your email, and keep you up to date on the latest network newsgroup postings. You can also use it to issue commands to the command shell, compile and debug programs, and play games without ever having to leave the editor's workspace.
|
Page 1 of 1 | |
Introduction
In the last Linux editor article, Easing Into Editors: vim, we took a look at some of the basics of using one of the "standard" text editors, vim, that is available by default on most Linux/Unix systems. We started off by discussing the fact that a lot of the work done in Linux is done in an editor of some sort. This makes it imperative that users jump into learning how to use those editors with both feet. We also learned that, despite appearances, vim is relatively straightforward, and after some practice, becomes quite easy to use while remaining a very powerful text editor. Working with text files is its sole job, and it does it very well. In this article, we are going to be discussing the emacs editor. While we learned that the vim editor is primarily concerned with unadorned text files, the emacs editor is capable of a lot more than simple text file editing. Emacs can do virtually anything that you would want to do on a computer without having launch a separate program (I am sure that someone has even customized a "butter your toast" meta-function). It is that powerful! It can check, display, and manage your email, and keep you up to date on the latest network newsgroup postings. You can also use it to issue commands to the command shell, compile and debug programs, and play games without ever having to leave the editor's workspace. Because of all of this functionality and versatility, mastering the emacs editor can be akin to mastering calculus or trigonometry. It is not impossible, but it can take a lot of time and trial and error. However, if in the end, you want something that can do it all (maybe you want to slip the surly bonds of straight text editing), then emacs is just what you ordered. For the purposes of this article and to make it easier on ourselves, we will just be focusing primarily on editing simple files (such as quick notes or Linux configuration files). Once you have mastered that, you can start out on the never-ending quest towards mastering all of emacs' other parts, functions and intricacies. A Brief History... Emacs originally stood for Editor MACroS. Back then, it was just a bunch of editor commands and macros that were strung together for another less functional text editor of the time. It seems like everyone has since tried to make a more sensible acronym of emacs, including Eight Megabytes And Constantly Swapping or, in a nod to emacs' "keyboard kung fu," ESCAPE META ALT CONTROL SHIFT. Since then, emacs evolved into a software project all of its own with Richard Stallman (the founder of the Free Software Foundation, to whom Linux owes its development tool roots) at its helm. Emacs began its evolution before the X window system as Stallman's attempt to create a "windowed" environment and workspace. It is now in its 19th (plus) version and can handle tasks ranging from editing text files to compiling programs and reading newsgroups. Written in the C language (for portability between systems), emacs has a variation of the LISP computer language interpreter at its core that allows it to be extended in almost any way imaginable. In the end, if you don't like the way it works, you can invest a little time and make it work the way you'd like. How emacs Compares With vim Since we started with the vim editor, we should show how they differ from each other. As we have already discussed, the emacs editor is "feature rich", to say the least. It handles text in as skillful a manner as the vim editor, but also includes programmed facilities for working with text layout via the TeX/LaTeX layout tool set. Both editors are visually based, versus command-line, allowing for file edits to occur with a knowledge of their context.
One of the main differences between the editors is the concept of modes. As we discussed in the first article, vim works in a number of modes depending on whether you are adding or manipulating text. Generally, users switch between modes with the The other major difference of the emacs editor is its inclusion of a LISP interpreter into its repertoire of tools, which allow for it to be molded in any way that the end user sees fit. We won't go into this, but there are detailed help files available at the Free Software Foundation that can guide you through the process, should you be so inclined later. That should do it for background basics and comparisons, let's take a look at how to do some work with emacs. Starting the emacs Editor Generally, in a command shell, the syntax for starting up the emacs editor to work with a new file (or for working with a file already in existence is:
However, if you are working in the X windows system, and you only want to work with the terminal based version of emacs, you'll need it tell it to ignore the X windows system with the following command line switch (or option):
For our purposes, we will be working with a file named fstep.emacs, so we type:
This will open the emacs editor for working with the fstep.emacs file. You should see something that looks a little something like this:
...cut for space...
----:---F1 fstep.emacs (Fundamental)--L1---All-----------
(New file)
Other emacs startup options include: starting emacs without your customized .emacs file ( Now let's look at adding some text to fstep.emacs. Adding Text in emacs: Let's add the party line definition of Linux to our file. We'll again borrow (for consistency) the initial definition from the FirstStep section of Linux.com (http://www.linux.com/firststep/#whatislinux).In case you didn't see it last time, here's what it says: Linux, the most popular Unix variant for PCs, is the only operating system not from Microsoft that is gaining significant market share. Created by Linus Torvalds and developed collaboratively over the Internet, Linux is the great success story of Open Source software development.
Inserting text into a file with the emacs editor is a simple matter of typing at any time. Since the editor is modeless it does not require you to enter a separate mode before you can enter text. Just start typing. It is pretty much that simple. One thing to note is that you should use the
...cut for space...
----:---F1 fstep.emacs (Fundamental)--L5---All------------------------
(New file)
That should have been pretty easy. At least we didn't have to worry about which mode we were in that time. Before we do anything else, let's save these changes to the file. Again, since emacs doesn't have modes, there is no need to do anything other than issuing the editors save command, which is the Now it's time to look at the tools we will need to actually make changes to the files that we have created. In order to edit the file, we are going to have to learn how to maneuver around inside of it until we get to the position where the edit needs to occur. That's what we'll cover next. Moving the Cursor in emacs
Basic cursor movement in the emacs editor is just as straightforward as in the vim editor, if not more so since you don't have to switch modes to do it. You can move anywhere in your file by using the
Larger documents may require a lot more work and single space cursor movements are going to wear your keyboard out in a hurry. For these types of situations, there is a broader set of movement tools. Emacs includes facilities for moving forward or backward on word at a time ( Let's cover a few commands for cutting, pasting and removing text, and then we'll apply what we've learned to fstep.emacs. Some Editing Commands for emacs:
Many people have worked with word processing programs at least once or twice in the past (if not, don't worry) and may have become accustomed to cutting, copying and pasting text in and about word processed documents. The keyboard combinations for those functions in most of those word processors are
To cut or copy text in emacs, you first have to "mark" the text that you want to manipulate. To "mark" the text that your want to work with, move the cursor to the beginning of the text block and type
To place the text block that you have copied or cut, just use your cursor movement commands to get the cursor into the place where you want the text to go. Once there, simply type
Emacs offers a number of tools for manipulating the text of a file in a number of ways. There are a number of keyboard combinations that facilitate the deletion of text from the editor. To delete the character before the cursor, you can use the
If your typing has ever got ahead or behind your thinking, you've surely run into the situation of simple transposition typos where two letters or two words are in the wrong order. This is common enough that emacs offers two commands to take care of this. Now, let's apply some of what we learned. An Example Using emacs We're going to change the first line of our example into two separate sentences (this is already sounding like a standardized test). When we last left fstep.emacs, it looked like this:
...cut for space...
----:---F1 fstep.emacs (Fundamental)--L5---All-----------------------
(New file)
In order to edit the first sentence we are going to have to get the cursor up there. To move to the beginning of the paragraph, you can type the
...cut for space...
----:---F1 fstep.emacs (Fundamental)--L1---All--------------------------
(New file) You should now see the cursor over the "L" in "Linux" as above.
Now use the arrow keys (or other movement commands we've discussed) to move the cursor over both commas in this sentence and delete them with the
into these sentences:
When you are all done it should look something like this:
...cut for space...
----:---F1 fstep.emacs (Fundamental)--L1---All-----------------------
(New file)
You can quit and save your changes by typing
That's it for now. I hope you will give emacs a chance in your future explorations with Linux. While it is tough to learn, it can be quite powerful and does away with mode-based editing, the major complaint of some other editors, *cough*vim*cough*. While this is by no means an exhaustive look at emacs, it should give you enough commands to get you started and keep you from an emacs-induced migraine. For further information on the editor you can type
| |
Page 1 of 1 |