Editing Text


Because Unix and Linux are rooted in the hacker/geek/programmer culture, where coding was (and is) the most important function of any computer, having robust shells and editors were essential parts of the experience. It is no accident that Bill Joy wrote both the C shell and the vi editor, nor that Richard Stallman created the GNU Project and the emacs editor (and that each has completely different views about how to create and license software).

Of course, that was in the bygone early days of Unix. Why does it matter what text editor you should use now? And why do you need one, anyway? Consider this: Word processors are wonderful things, but often they are the very essence of overkill. One of the beauties of Linux is that nearly all the configuration and customization options for applications are contained in simple text files. This is true whether the program has a GUI or not. So making changes in the way a program works doesn't necessarily have to require opening the program; just open the config file in a text editor!

There's one other reason to be at least somewhat comfortable with at least one nongraphical editor. One of the truly cool things about Linux is the capability to access many different computers regardless of where you happen to physically be located at a given moment.

Remote access to other servers and workstations is another beauty of Linux, but most times, those remote machines (especially the servers) don't even have X installed. To get any work done, you need a text editor.

SUSE Linux offers no fewer than 22 text editors through YaST, as shown in Table 5.1. Don't be overwhelmed by the number of choices, though. Basically, text editors fall into one of two major camps: editors that behave like vi and editors that behave like emacs. This list also has a few line editors that work directly in the shell.

Table 5.1. Types of Editors in SUSE Linux

Vi-type

Emacs-type

Other

Vim

Emacs

Ed

Gvim

Xemacs

Joe

Nvi

TeXmacs

Pico

Kvim

Uemacs

E3

 

Zile

FTE

 

Qemacs

Mined

  

THE (the Hessling Editor)

  

JEdit


The next few sections will help you work with these various editors.

Working with vim and Its Clones

They say that vi is hard to learn, but once you get there, you can do amazing things with it. That hard-to-learn part is evident from the first time you use it (unless you have a vi user nearby). When you first open the vi editor (and these days, typing vi actually opens its "improved" version, vim), you cannot type anything. By default, vi opens in its command/viewing mode. You can maneuver around a file, provided you know that commands in vi begin with a colon (:). To edit a file, you must press the Insert key (or Esc-i) first.

After you know this secret handshake, vim can be very useful and, with practice, very powerful. It also comes with extensive documentation. The documentation page at the Vim.org site says it best: "The most useful software is sometimes rendered useless by poor or altogether missing documentation. Vim refuses to succumb to death by underdocumentation."

To quickly get up to speed in vim, you don't have to run the editor. Run vimtutor from the shell prompt to get a brief tutorial, estimated to take about 30 minutes to complete.

Following are a few commands that will help you get started with vim:

Simple navigation: Your arrow keys work fine, but these characters also move the cursor:

h

left

 

l

right

 

k

up

 

j

down

 

Delete character

x

Delete line

dd

Save

:w (write)

Find text in file

/<string>

Changing mode from Insert to Command

Esc

Quit

:q

Quit without saving

:q!


Gvim and Kvim both offer GUIs for the basic editor. They were written for GNOME and KDE, respectively, but you can use either one in either environment. The primary development team for Kvim has moved on to produce another GUI-based vi clone called Yzis.

Nvi is a slightly different version of vi from the University of California at Berkeley.

Working with Emacs and Its Clones

GNU emacs is the infinitely customizable, everything-but-the-kitchen-sink editor/work environment. It was the first product of the GNU Project, and so is beloved by many free-software purists.

It is the text editor that keeps your hands busy over the keyboard with seemingly odd multiple keybindings (Ctrl+X to begin a command and another combination to complete it). Learning emacs is a supremely geeky thing to do.

If vim has everything an editor should have in one pretty, if sometimes impenetrable, package, emacs is a modular monster. Emacs reads email and Usenet newsgroups, browses the web and composes web pages in HTML, XHTML, XML, and sundry other formats as well. It offers a development environment for practically every extant programming language. You can even see a sublimely odd conversation between Zippy the Pinhead and a psychoanalyst. But to do all this, you must have the proper mode installed. Emacs is a big program (taking up to 30MB), but it does not include every mode that has been written. Sometimes you have to go hunting for the thing you need.

Emacs is easy to start up (type emacs <filename> from the shell prompt), and navigation can be pretty easy.

Unlike vim, Emacs has its own interface (vim just shows up in the shell) with menus and mouse support, although not quite as pretty as under X. Unless you include a mode command when you launch it, emacs assumes you want to write text and loads in text fill mode. If you don't want words to wrap at the end of a line, go to the Options menu or type Alt+X+auto-f[TAB] to change the mode.

Emacs also has a tutorial that will walk you through the basic commands and navigation tools. In emacs, use Ctrl+H, and then press "T" to get to it.

Most of the other clones of emacs (aficionados use the plural emacsen) are subsets of the original designed for specific uses. XE began as a GUI version, but has a separate group of developers that have done some things differently from its parent. Generally speaking, XEmacs is faster to add new features and does not require packagers to assign copyright to the Free Software Foundation (that administers the GNU Project).

Some of the Others

You don't need to follow the crowd when choosing an editor. Choices are not limited to the big two. Take these for a spin:

  • ed The first Unix line editor. It opens by default in viewing/command mode and is the reason vi does the same.

    You could put it in the vi-clones category, if it didn't predate vi. If you need a shell script to edit or perform commands on some text, ed is the editor to invoke. It's fast and functional for basic line editing.

  • Joe You say you can't decide whether emacs or vi is cooler? Do you still remember all those WordStar commands and macros? You just might love Joe's Own Editor. Joe is a flexible beast that wants to work the way you want it to. It can emulate any of the previously mentioned editors with a simple command switch. You can open and edit multiple files at once and provide different environments for each one. Like emacs, it can read email and news, too. Help is extensive and can put a command template right on your screen so you don't have to think about how to save a file (Ctrl+K, and then D, if you must know).

  • JEdit This is a Java-based graphical editor that many folks swear by. Although powerful by itself, it also has a plug-in architecture that can bulk it up even more. The nice thing is that it is incredibly easy to add and update any plug-in you have with the built-in plug-in manager. The commands are relatively easy to learn, and the user's guide is helpful.

  • The Hessling Editor (the) This is a specialized editor for people used to working in VMS/CMS and another example of how niches get served in an open-source environment. There may not be millions of VMS veterans with wallet in hand transitioning to Linux, but it takes only one person with some programming skills to write that editor and make it available to the rest of us.



SUSE Linux 10 Unleashed
SUSE Linux 10.0 Unleashed
ISBN: 0672327260
EAN: 2147483647
Year: 2003
Pages: 332

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