< Day Day Up > |
Traditionally, most Linux distributions, including Red Hat, install the cursor-based editors Vim and Emacs. Vim is an enhanced version of the Vi text editor used on the Unix system. These editors use simple, cursor-based operations to give you a full-screen format. You can start these editors from the shell command line without any kind of X Window System support. In this mode, their cursor-based operations do not have the ease of use normally found in window-based editors. There are no menus, scroll bars, or mouse-click features. However, the K Desktop and GNOME do support powerful GUI text editors with all these features. These editors operate much more like those found on Macintosh and Windows systems. They have full mouse support, scroll bars, and menus. You may find them much easier to use than the Vi and Emacs editors. These editors operate from their respective desktops, requiring you first have either KDE or GNOME installed, though the editors can run on either desktop. Vi and Emacs have powerful editing features that have been refined over the years. Emacs, in particular, is extensible to a full-development environment for programming new applications. Newer versions of Emacs, such as GNU Emacs and XEmacs, provide X Window System support with mouse, menu, and window operations. They can run on any window manager or desktop. In addition, the gvim version of the Vim editor also provides basic window operations. Red Hat also includes a very easy to use GUI-based text editor called Nedit. You can access it on both GNOME and KDE desktops. Table 11-7 lists several GUI-based editors for Linux.
Note |
Red Hat Linux includes three fully functional word processors, OpenWriter, KWord and AbiWord. You can find out more on AbiWord at www.abiword.com. |
The gedit editor is a basic text editor for the GNOME desktop. It provides full mouse support, implementing standard GUI operations, such as cut and paste to move text, and click and drag to select text. It supports standard text editing operations such as Find and Replace. You can use gedit to create and modify your text files, including configuration files. gedit also provides more advanced features such as print preview and configurable levels of undo/redo operations, and it can read data from pipes. It features a plug-in menu that provides added functionality, and it includes plug-ins for spell-checking, encryption, e-mail, and text-based Web page display.
The K Desktop |
Description |
---|---|
KEdit |
Text editor |
Kate |
Text and program editor |
KJots |
Notebook editor |
KWord |
Desktop publisher, part of KOffice |
GNOME | |
gedit |
Text editor |
AbiWord |
Word processor |
Nedit |
GUI-based text editor |
X Window System | |
GNU Emacs |
Emacs editor with X Window System support |
XEmacs |
X Window System version of Emacs editor |
gvim |
Vim version with X Window System support |
OpenWriter |
OpenOffice word processor that can edit text files |
All the K Desktop editors provide full mouse support, implementing standard GUI operations, such as cut and paste to move text, and click and drag to select text. Kate is an advanced editor, with such features as spell-checking, font selection, and highlighting. Most commands can be selected using menus. A toolbar of icons for common operations is displayed across the top of the Kate window. A sidebar displays panels for a file selector and a file list. With the file selector, you can navigate through the file system selecting files to work on. Kate also supports multiple views of a document, letting you display segments in their own windows, vertically or horizontally. You can also open several documents at the same time, moving between them with the file list.
Kate is designed to be a program editor for editing software programming/development- related source code files. Although Kate does not have all the features of Emacs or Vi, it can handle most major tasks. Kate can format the syntax for different programming languages, such as C, Perl, Java, and XML. In addition, Kate has the capability to access and edit files on an FTP or Web site.
KEdit is an older simple text editor meant for editing simple text files such as configuration files. A toolbar of buttons at the top of the KEdit window enables you to execute common editing commands easily using just a mouse click. With KEdit, you can also mail files you are editing over a network. The entry for KEdit in the K menu is listed simply as Text Editor. You can start up KEdit by entering the kedit command in a terminal window. The KOffice Office Suite also includes a word processor called KWord, which is a high-powered word processor you can also use as a simple editor.
The editor KJots is designed to enable you to jot down notes in a notebook. It organizes notes you write into notebooks, called simply books. You can select the one you want to view or add to from the Books menu. To start KJots, select its entry in the Utilities menu or enter the kjots command in a terminal window.
Emacs can best be described as a working environment featuring an editor, a mailer, a newsreader, and a Lisp interpreter. The editor is tailored for program development, enabling you to format source code according to the programming language you use. Many versions of Emacs are currently available for use on Unix and Linux systems. The versions usually included with Linux distributions are either GNU Emacs or XEmacs. The current version for GNU Emacs is 20.x; it is X Window System–capable, enabling GUI features such as menus, scroll bars, and mouse-based editing operations. (See Chapter 13 for a discussion of the GNU Emacs mailer and its newsreader.) Check the update FTP sites for your distribution for new versions as they come out, and also check the GNU Web site at www.gnu.org and the Emacs Web site at www.emacs.org. You can find out more information about XEmacs at its Web site, www.xemacs.org.
Emacs derives much of its power and flexibility from its capability to manipulate buffers. Emacs can be described as a buffer-oriented editor. Whenever you edit a file in any editor, the file is copied into a work buffer, and editing operations are made on the work buffer. Emacs can manage many work buffers at once, enabling you to edit several files at the same time. You can edit buffers that hold deleted or copied text. You can even create buffers of your own, fill them with text, and later save them to a file. Emacs extends the concept of buffers to cover any task. When you compose mail, you open a mail buffer; when you read news, you open a news buffer. Switching from one task to another is simply a matter of switching to another buffer.
The Emacs editor operates much like a standard word processor. The keys on your keyboard represent input characters. Commands are implemented with special keys, such as control (CTRL) keys and alternate (ALT) keys. There is no special input mode, as in Vi or Ed. You type in your text, and if you need to execute an editing command, such as moving the cursor or saving text, you use a CTRL key. Such an organization makes the Emacs editor easy to use. However, Emacs is anything but simple—it is a sophisticated and flexible editor with several hundred commands. Emacs also has special features, such as multiple windows. You can display two windows for text at the same time. You can also open and work on more than one file at a time, and display each on the screen in its own window. You invoke the Emacs editor with the command emacs. You can enter the name of the file you want to edit, and if the file does not exist, it is created. In the next example, the user prepares to edit the file mydata with Emacs:
$ emacs mydata
The GNU Emacs editor now supports an X Window System graphical user interface. To enable X support, start Emacs within an X Window System environment, such as a KDE, GNOME, or FVWM desktop. The basic GUI editing operations are supported: selection of text with click-and-drag mouse operations; cut, copy, and paste; and a scroll bar for moving through text. The Mode line and Echo areas are displayed at the bottom of the window, where you can enter keyboard commands. The scroll bar is located on the left side. To move the scroll bar down, click it with the left mouse button. To move the scroll bar up, click it with the right mouse button.
Note |
XEmacs is the complete Emacs editor with a graphical user interface and Internet applications. The Internet applications, which you can easily access from the main XEmacs button bar, include a Web browser, a mail utility, and a newsreader. |
The Vim editor included with most Linux distributions is an enhanced version of the Vi editor. It includes all the commands and features of the Vi editor. Vi, which stands for visual, remains one of the most widely used editors in Linux. Keyboard-based editors like Vim and Emacs use a keyboard for two different operations: to specify editing commands and to receive character input. Used for editing commands, certain keys perform deletions, some execute changes, and others perform cursor movement. Used for character input, keys represent characters that can be entered into the file being edited. Usually, these two different functions are divided among different keys on the keyboard. Alphabetic keys are reserved for character input, while function keys and control keys specify editing commands, such as deleting text or moving the cursor. Such editors can rely on the existence of an extended keyboard that includes function and control keys. Editors in Unix, however, were designed to assume a minimal keyboard with alphanumeric characters and some control characters, as well as the ESC and ENTER keys. Instead of dividing the command and input functions among different keys, the Vi editor has three separate modes of operation for the keyboard: command and input modes, and a line editing mode. In command mode, all the keys on the keyboard become editing commands; in the input mode, the keys on the keyboard become input characters. Some of the editing commands, such as a or i, enter the input mode. On typing i, you leave the command mode and enter the input mode. Each key now represents a character to be input to the text. Pressing ESC automatically returns you to the command mode, and the keys once again become editor commands. As you edit text, you are constantly moving from the command mode to the input mode and back again. With Vim, you can use the CTRL-O command to jump quickly to the command mode and enter a command, and then automatically return to the input mode. Table 11-8 lists a very basic set of Vi commands to get you started.
Key |
Cursor Movement |
---|---|
h |
Moves the cursor left one character. |
l |
Moves the cursor right one character. |
k |
Moves the cursor up one line. |
j |
Moves the cursor down one line. |
CTRL-F |
Moves forward by a screen of text; the next screen of text is displayed. |
CTRL-B |
Moves backward by a screen of text; the previous screen of text is displayed. |
Input |
(All input commands place the user in input; the user leaves input with ESC.) |
a |
Enters input after the cursor. |
i |
Enters input before the cursor. |
o |
Enters input below the line the cursor is on; inserts a new empty line below the one the cursor is currently on. |
Text Selection (Vim) |
Cursor Movement |
v |
Visual mode; move the cursor to expand selected text by character. Once selected, press key to execute action: c change, d delete, y copy, : line editing command, J join lines, U uppercase, u lowercase. |
V |
Visual mode; move cursor to expand selected text by line. |
Delete |
Effect |
x |
Deletes the character the cursor is on. |
dd |
Deletes the line the cursor is on. |
Change |
(Except for the replace command, r, all change commands place the user into input after deleting text.) |
cw |
Deletes the word the cursor is on and places the user into the input mode. |
r |
Replaces the character the cursor is on. After pressing r, the user enters the replacement character. The change is made without entering input; the user remains in the Vi command mode. |
R |
First places into the input mode, and then overwrites character by character. Appears as an overwrite mode on the screen, but actually is in input mode. |
Move |
Moves text by first deleting it, moving the cursor to desired place of insertion, and then pressing the p command. (When text is deleted, it is automatically held in a special buffer.) |
p |
Inserts deleted or copied text after the character or line the cursor is on. |
P |
Inserts deleted or copied text before the character or line the cursor is on. |
dw p |
Deletes a word, and then moves it to the place you indicate with the cursor (press p to insert the word after the word the cursor is on). |
yy or Y p |
Copies the line the cursor is on. |
Search |
The two search commands open up a line at the bottom of the screen and enable the user to enter a pattern to be searched for; press ENTER after typing in the pattern. |
/pattern |
Searches forward in the text for a pattern. |
?pattern |
Searches backward in the text for a pattern. |
n |
Repeats the previous search, whether it was forward or backward. |
Line Editing Commands |
Effect |
w |
Saves file. |
q |
Quits editor; q! quits without saving. |
Although the Vi command mode handles most editing operations, it cannot perform some, such as file saving and global substitutions. For such operations, you need to execute line editing commands. You enter the line editing mode using the Vi colon command. The colon is a special command that enables you to perform a one-line editing operation. When you type the colon, a line opens up at the bottom of the screen with the cursor placed at the beginning of the line. You are now in the line editing mode. In this mode, you enter an editing command on a line, press ENTER, and the command is executed. Entry into this mode is usually only temporary. Upon pressing ENTER, you are automatically returned to the Vi command mode, and the cursor returns to its previous position on the screen.
Although you can create, save, close, and quit files with the Vi editor, the commands for each are not all that similar. Saving and quitting a file involves the use of special line editing commands, whereas closing a file is a Vi editing command. Creation of a file is usually specified on the same shell command line that invokes the Vi editor. To edit a file, type vi or vim and the name of a file on the shell command line. If a file by that name does not exist, the system creates it. In effect, giving the name of a file that does not yet exist instructs the Vi editor to create that file. The following command invokes the Vi editor, working on the file booklist. If booklist does not yet exist, the Vi editor creates it.
$ vim booklist
After executing the vim command, you enter Vi's command mode. Each key becomes a Vi editing command, and the screen becomes a window onto the text file. Text is displayed screen by screen. The first screen of text is displayed, and the cursor is positioned in the upper-left corner. With a newly created file, there is no text to display. This fact is indicated by a column of tildes at the left side of the screen. The tildes represent the part of a screen that is not part of the file.
Remember, when you first enter the Vi editor, you are in the command mode. To enter text, you need to enter the input mode. In the command mode, a is the editor command for appending text. Pressing this key places you in the input mode. Now the keyboard operates like a typewriter and you can input text to the file. If you press ENTER, you merely start a new line of text. With Vim, you can use the arrow keys to move from one part of the entered text to another and work on different parts of the text. After entering text, you can leave the input mode and return to the command mode by pressing ESC. Once finished with the editing session, you exit Vi by typing two capital Z's, ZZ. Hold down the SHIFT key and press Z twice. This sequence first saves the file and then exits the Vi editor, returning you to the Linux shell. To save a file while editing, you use the line editing command w, which writes a file to the disk; w is equivalent to the Save command found in other word processors. You first type a colon to access the line editing mode, and then type w and press ENTER.
You can use the :q command to quit an editing session. Unlike the ZZ command, the :q command does not perform any save operation before it quits. In this respect, it has one major constraint. If any modifications have been made to your file since the last save operation, the :q command will fail and you will not leave the editor. However, you can override this restriction by placing a ! qualifier after the :q command. The command :q! will quit the Vi editor without saving any modifications made to the file in that session since the last save (the combination :wq is the same as ZZ).
To obtain online help, enter the :help command. This is a line editing command. Type a colon, enter the word help on the line that opens at the bottom of the screen, and then press ENTER. You can add the name of a specific command after the word help. The F1 key also brings up online help.
As an alternative to using Vim in a command line interface, you can use gvim, which provides X Window System–based menus for basic file, editing, and window operations. To use gvim, enter the gvim command at an X Window System terminal prompt or select it from a window manager menu. The standard Vi interface is displayed, but with several menu buttons displayed across the top. All the standard Vi commands work just as they are described previously. However, you can use your mouse to select items on these menus. You can open and close a file, or open several files using split windows or different windows. The editing menu enables you to cut, copy, and paste text as well as undo or redo operations. In the editing mode, you can select text with your mouse with a click-and-drag operation, or use the Editing menu to cut or copy and then paste the selected text. Text entry, however, is still performed using the a, i, or o commands to enter the input mode.
< Day Day Up > |
This HTML Help has been published using the chm2web software. |