299 304




Linux Unleashed, Third Edition:Text Editors: vi and emacs





-->















Previous
Table of Contents
Next




Part IIIEditing, Typesetting, and More


In This Part
•   Text Editors: vi and emacs
•   groff
•   geqn and gtbl
•   TeX and LaTeX
•   Printing
•   Multimedia Linux

Chapter 16Text Editors: vi and emacs

by Peter MacKinnon

In This Chapter
•   What are editors and why do I need one?
•   The editing functions
•   The vi editor
•   The emacs editor

What Are Editors and Why Do I Need One?
A text editor is one of the most essential tools provided with the Linux (or virtually any) operating system. With an editor, you can create and modify text files that have a wide variety of applications:

•  User files such as .login and .cshrc
•  System files
•  Shell programs
•  Documents
•  Mail messages

These are but a few of the many different types of text files that you will use when working with Linux. Basically, editors enable you to insert, delete, move, and search text ranging from individual characters to thousands of lines.

Two of the most popular editors for the Linux system are emacs and vi. These editors are both full-screen text editors; put simply, they use every row and column of your terminal screen to display the textual contents of a file. Both of these editors feature a rich set of commands. The essential commands for manipulating text can be learned reasonably quickly; the more sophisticated commands may take a little longer to master. However, you will likely appreciate this investment as you see how much time these powerful tools can save you.
Choosing one editor over another can be a matter of taste. Both emacs and vi are efficient and can handle virtually any size file. The emacs editor is better suited to complex editing tasks and comes with an online help facility, but for simple editing jobs, either editor is equally good. It comes down to whichever one you feel more comfortable using.
The Editing Functions
Although there are a variety of text editors for Linux that have different interfaces, they all basically do the same things. Any useful text editor should support the following features at a minimum.

Inserting and Deleting Text
The most intrinsic function of a text editor is to allow you to enter and erase characters as you see fit. This also implies that you have complete control over the movement of the cursor and its placement in the text.

Reading and Writing Files
Because you will want to save the text files that you create for future use and reuse, an editor can write your text to an external file. Whenever you need to make changes to your file, an editor can read the file from disk. A nice feature is that text editors are designed to accommodate ASCII-formatted files, so an editor (such as emacs) can read any file written by another editor (such as vi), and vice versa.
Searching Text
Personally scanning line after line of a large file for instances of a particular word is either a great way to improve your powers of concentration or an exercise in self-torture. That is why text editors provide sophisticated search capabilities. These include the use of regular expressions, as well as fixed strings. Remember that regular expressions include metacharacters (such as ., ?, and *) that replace and expand unknown text patterns.
Editors also support search-and-replace functions that allow you to change multiple instances of a string pattern with a single command.
Copying and Moving Text
Because there is no guarantee that the way text is initially typed into a file is the way it should forever remain, editors provide you with the means to copy, cut, and move (or paste) blocks of text. These blocks can range in size from several pages to a single character. The distinction between copying and cutting text is that cutting deletes the selected block of text after it has been copied to a buffer, whereas copying does not.

Editing Buffers
What is a buffer, you ask? Buffers are places in the memory of the editing program where text can reside as you make changes to a file. For example, the first time you edit a file, the text you have entered actually exists in a buffer that is written to an external file when you do a save. Buffers can also be used at other times in editing, particularly when it is necessary to temporarily move a block of text to memory as you make changes (in other words, cutting and pasting). Many editors allow you to manage multiple buffers simultaneously.
These editors have many commands that are not fully detailed in this chapter. Before engaging in any long and arduous editing task, consult the man page for the editor you are using. There may be an easier way of doing whatever it is that you want to do. As you gain experience with an editor, you will discover convenient shortcuts and functions to perform your most tedious editing chores.
The vi Editor
The vi editor is installed with virtually every UNIX system in existence. Because of this, vi is considered by many to be the default text editor of the UNIX system (upon which Linux is based). vi has two modes of operation and terse commands, both of which make it a somewhat more difficult editor to learn than emacs. However, it is a useful editor to learn if emacs has not been installed on your Linux system.



Previous
Table of Contents
Next














Wyszukiwarka

Podobne podstrony:
299 304
304 307
13 (304)
29922
29925
16 (304)
304 34
296 299
readme (299)
301 304

więcej podobnych podstron