[Next] [Previous] [Up] [Top] [Contents] [Index]
Chapter 11: Editors
In this section we present a few important commands for each editor. The minimal information necessary for you to edit and save a simple file is provided. All these editors have many commands and sophisticated features that we do not cover here.
As we mentioned in section 11.1 above, you may occasionally find yourself thrown into the vi editor unexpectedly, and you will certainly want to know how to exit, if nothing else. For that reason alone you should become familiar with a few vi commands. As is typical in UNIX, the vi commands are case sensitive.
vi requires no setup. Invoke it using the command:
% vi [filename]
Once the file is opened, you are in command mode. From this mode you can issue commands, move the cursor, and invoke insert mode.
To enter insert mode, type i. Text you type will be inserted before the cursor. From insert mode you can enter new text in the file. Press the Escape key to exit insert mode and return to command mode. On many keyboards the Escape key is labelled; if not, the sequence <Ctrl-[> is mapped to the escape function.
h,j,k,l move cursor left, down, up, right, respectively
H move to top line of screen
L move to bottom line of screen
scroll forward, backward one screen
/pattern search for pattern
/ repeat search in forward direction
x delete current cursor position
X delete back one character
dw delete current word
dd delete current line
dd delete n lines starting with current
p insert (paste) last deleted text after cursor
:r filename read in contents of filename after cursor
:x quit vi, writing file only if changes were made
:w write file, do not quit
:w file save copy to file, do not quit
:q! quit file, discarding edits
Most UNIX guides contain a complete description of vi.
We'll cover these two editors in the same section because although they are separate products, they are closely related.
emacs is a popular editor available on the net. It can be invoked in windows mode or ASCII mode. Many UNIX books cover emacs, and a good reference for GNU emacs is Learning GNU Emacs (O'Reilly & Associates). We also refer you to an on-line GNU EMACS manual accessible under Editors on the UNIX Resources Web page. Further documentation can be found from the man pages.
To use emacs, the product needs to be installed. To set it up, include in your login script or enter:
% setup emacs
The mode (X or ASCII) in which emacs attempts to start-up is determined according to your DISPLAY variable. To invoke, type:
% emacs [options] [filename]
To invoke it in ASCII mode without a new window using an X terminal, type:
% emacs -nw [options] [filename]
To use xemacs, the product needs to be installed. To set it up, include in your login script or enter:
% setup xemacs
To invoke xemacs, type:
% xemacs [filename] [&]
emacs/xemacs has an extensive interactive help facility, but the facility assumes that you know how to manipulate emacs windows and buffers. <Ctrl-h> enters the Help facility. <Ctrl-h>-t enters the help tutorial, which can teach beginners the fundamentals of emacs in a few minutes. <Ctrl-h>-a enters Help Apropos, to help you find commands by function. For emacs in windows mode, there is also a Help menu. <Ctrl-h>-i enters the Info facility which brings up the on-line documentation browsing system. The initial page (the Directory node) gives a menu of major topics. The information is presented in a hierarchical tree format. xemacs provides this via an Info button.
emacs/xemacs commands use the Control key and the Meta key[54]. In the following list C- indicates that the control key is pressed at the same time as the character that follows. Similarly, M- indicates the use of the Meta key, although it's not necessary to keep the Meta key pressed down while typing the next character. Note that some command sequences use multiple keystrokes, with and without the Control and Meta keys. A sequence like C-x u means hold down control while you press x, then just press u. Following is a list of the emacs commands used most often:
C-h enter on-line help system
C-h i enter the information browser which provides a menu of major topics (use tab and enter keys or 2nd mouse button to select a topic; navigation information is provided)
C-p, C-n, C-f, C-b move up (to previous), down (to next), forward, or backward by one line or character, respectively
C-v, M-v move forward, backward, by one screen
C-s search forward for characters (system will prompt you for string). To continue search, type C-s again.
C-r search backward
C-d delete a character
C-k delete (kill) from cursor to end of line
C-y restore what you've deleted
C-x u undo last edit
C-g get out of current command operation
C-x i insert file at cursor position (system will prompt for filename)
M-q fill paragraphs
C-@ or C-spacebar set the mark for the start or end of a region to select
C-w delete all between mark (see C-@) and cursor's current position (paste back with C-y)
M-w copy all between mark (see C-@) and cursor's current position (paste back with C-y)
C-x C-x exchange mark and cursor's current position (since the mark is invisible, this allows you to find it)
C-x C-s save the file
C-x C-w write to file (system will prompt for filename)
C-x C-b display buffer list
C-x o move cursor to other window (when more than one displayed)
C-x C-c exit emacs
Note, if the serial port or terminal device you are typing on is configured for <Ctrl-s>/<Ctrl-q> flow control, you may find that <Ctrl-s> (written above as C-s) within emacs causes the terminal to stop sending characters, the same as when used at the shell prompt. If you want to use the usual emacs key bindings and to have C-s work properly within emacs, you'll need to reconfigure your line to not do flow control. Where and how you do this depends on how you're connected. If you're connected via a modem, you may need to reconfigure your modem, as well as the pseudo-terminal on your UNIX host. The latter can be done via the command:
% stty stop undef start undef
(which sets the stop and start characters to "undefined"). You could include this statement in your .login or .profile. The intermediate step, between the on-site modem and the Cisco router/terminal server, has flow control turned off by default.
emacs/xemacs supports several text editing environments (called modes), each geared to a particular language (e.g., English, Lisp, C, FORTRAN). When the editor is started, it normally loads the file $HOME/.emacs, if present, which contains Lisp commands for initialization. In particular, by setting up a mapping in this file between file extensions and languages, you can configure emacs/xemacs to come up in the appropriate mode according to the extension of the file you specify on the invoking command line. The text you need to include in .emacs has the syntax:
(setq auto-mode-alist (append '(
("\\.extension1$" . language1-mode) ("\\.extension2$" . language2-mode)
("\\.extension3$" . language3-mode) ("\\.extension4$" . language4-mode)
...
) auto-mode-alist))
For example:
(setq auto-mode-alist (append '(
("\\.asm$" . asm-mode) ("\\.s$" . asm-mode) ("\\.awk$" . awk-mode)
("\\.cc$" . c++-mode) ("\\.C$" . cc-mode) ("\\.hh$" . c++-mode)
("\\.c$" . c-mode) ("\\.h$" . c-mode) ("\\.i$" . c-mode)
("\\.m$" . objc-mode) ("\\.csh$" . c-mode)
("\\.cdf$" . fortran-mode) ("\\.cin$" . fortran-mode)
("\\.for$" . fortran-mode) ("\\.f$" . fortran-mode) ("\\.F$" . fortran-mode)
("\\.inc$" . fortran-mode) ("\\.car$" . fortran-mode)
("\\.cra$" . fortran-mode) ("\\.crb$" . fortran-mode)
("\\.tex$" . TeX-mode) ("\\.txi$" . Texinfo-mode)
("\\.el$" . emacs-lisp-mode) ("\\.icc$" . c++-mode)
) auto-mode-alist))
The on-line GNU EMACS manual provides more information on creating and modifying this file.
emacs/xemacs can be set to have an EDT-style keypad. [Missing image]This is documented more thoroughly in our Web pages; here we provide some start-up information.
The key bindings are in the control of the editor emulation. When you first start up the tpu-edt emulator (instructions follow) it will prompt you to setup a keyboard mapping (see screen below). You need a separate mapping for each different keyboard type you use.
Here you are at the mercy of your window emulator. There are things you can do to remap keys on most vt100 window emulators, but it is different for each OS/emulator. There are too many permutations to document.
[Missing image]
To invoke the emulation, put the following text at the top of your $HOME/.emacs file:
(tpu-edt) ;; Basic Emulation
(tpu-set-scroll-margins "10%" "15%") ;; Set scroll margins 10% (top) and 15% (bottom).
(load "vt-control" t) ;; VT terminal controls (No complaint if not available)
;;
;; TPU-edt treats words like EDT; here's how to add word separators.
;; Note that backslash (\) and double quote (") are quoted with '\'.
(tpu-add-word-separators "]\\[-_,.\"=+()'/*#:!&;$")
To try this out without changing your .emacs file, first invoke the editor, then press Alt-x (hold down Alt while pressing x), and type tpu-edt followed by a carriage return.
[Missing image]On some platforms you may have trouble with the Gold key. The problem and its solution are dependent on the type of terminal and keyboard you are using. We know the solutions for some combinations. We are planning to provide this information soon in a Web page under UNIX Resources, and to keep it updated as we learn more. You may also find some helpful information under the heading X-terminals from the CD home page; see Misc. Information - Hints, Notes, User Experiences, Etc.
Due to the user-friendly nature of the product, we present only a few basic commands to give you a flavor of this type of editor if you are not familiar with it:
Open from the toolbar or File menu (you can also open in another window or in a new frame); choose an existing file from popup window
Open from the toolbar or File menu; type in the new file name
Insert File from the File menu
Use the mouse
Syntax Highlighting from Options menu.
Cut/Copy/Paste from the toolbar or Edit menu
Search from the Edit menu
Spell from the toolbar or Edit menu.
Save from the File menu
Delete Buffer from the File menu (use the Buffer menu to select the buffer to close)
Exit EMacs from the File menu
C-g get out of current command operation
The OO-Browser is a multi-windowed, interactive, object-oriented class browser. It currently supports seven object-oriented languages (Eiffel, C++, Objective-C, CLOS (Lisp), Java, Python and Smalltalk), one non-object-oriented language (C), and one documentation language, (GNU Info). [Missing image]On the Web you can find documentation for the oo-Browser with the xemacs product.
Before using the browser, you must create a database of information for each set of source code files you plan to use.
Here is a brief set of instructions for creating a database:
setup xemacs
outputdir), and invoke xemacs.
Load/Create OO-Browser Environment: {outputdir}/
Enter a filename. This file is used to store the answers to the following questions. The application will then read this file to build your browsing environment. The file can be reused in future sessions. Here we'll use the filename OOBR, to create the file {outputdir}/OOBR.
Choose: 1) C++/C; 2) Eiffel; 3) Info; 4) Java; 5) Lisp; 6) Obj-C; 7) Python; 8) Smalltalk
Enter the number corresponding to your choice.
Please specify the "OOBR" Environment (Hit RET to begin).
Enter Return as requested.
Build Environment from spec in file, "{outputdir}/OOBR"? (y or n)
Enter y
Build Environment in a background process? (y or n)
Enter n (in order to monitor what happens)
The oo-Browser starts scanning all of the files in the directory tree underneath the directories you specified. When it finishes, your database is made and you are ready to start browsing.
A couple of useful keys are f and v. f displays an expanded (full) summary of the member functions belonging to the selected class. If you enter v with the cursor on a class name, the source file that defines the class (usually a header file) is displayed for viewing. Enter e to display it for editing. If you enter v with the cursor on a member function name, it displays the source code for that member function (usually an implementation file). If there are many functions in the same file, the browser places you at the correct line number for the selected function.
NEdit is very similar in appearance and operation to many PC text processing applications for Windows. It is menu/mouse driven, with keyboard shortcuts available. Some UNIX shell commands are available from within the editor. Make sure the NEdit product is installed on your system. To set up NEdit, include in your login script or enter:
% setup nedit
To invoke NEdit, type:
% nedit [filename]
Due to the user-friendly nature of the product, we present only a few basic commands to give you a flavor of this type of editor if you are not familiar with it:
Open from the File menu; choose an existing file from popup window
New from the File menu
Include from the File menu
Use the mouse, or the shift and arrow keys together
Cut/Paste from the Edit menu
Find from the Search menu
Fill Paragraph from the Edit menu
spell from the Shell menu
Save from the File menu
Close from the File menu (you are prompted about saving)
Exit from the File menu
Further information is available from the man pages and a plain text document in the distribution kit, but the on-line help in the program is complete and more convenient. The documentation is also available on the Web in the product documentation area.
nu/TPU is an excellent port of Digital's TPU (Text Processing Utility) programming language to UNIX. The major component in nu/TPU is software that can be used to build new text processors and batch-oriented text manipulation routines. nu/TPU is distributed with two editing interfaces:
The product tpu needs to be installed prior to use. To set up nu/TPU, include in your login script or enter:
% setup tpu
To edit using the SI interface by default, type:
% tpu [filename]
To edit using the older EVE interface, enter:
% tpu -section=tpusec.ini [filename]
Once you are in the editor, on-line help is available via the PF2 key or the Help command.
For complete documentation on nu/TPU, including documentation on all command-line options and all nu/TPU programming statements, you can order the nu/TPU Reference Manual. Look under Editors on the UNIX Resources Web page for documentation on the TPU-edt editor for GNU Emacs.
The fermitpu product is layered upon nu/TPU and contains a locally developed port of Digital's EVE editing interface from VMS V6.1 (the version of VMS which is current during the VMS to UNIX migration). Note that this is not the same as the VMS product fermitpu, which contains many enhancements beyond the VMS V6.1 EVE editor. Users who are familiar with programming in EVE and TPU will probably be most comfortable with this editing interface.
The products fermitpu and nu/TPU must be installed prior to use. To invoke, include in your login script or enter:
% setup fermitpu % tpu [options] [filename]
Once you are in fermitpu, the on-line help (accessible via PF2 or the Help command) contains documentation on all of the EVE callbacks and TPU built-ins.
Look under Editors on the UNIX Resources Web page for documentation on the TPU-edt editor for GNU Emacs.
[Missing image]Support for EDT under UNIX is now frozen at release v6_3a.
This is a clone of Digital's EDT which includes the enhancement to remove the hard-coded 24-line display limit. The product edt needs to be installed. To setup EDT+, include in your login script or enter:
% setup edt
To invoke for editing within the same terminal window, type:
% edt [options] [filename]
To edit in a separate display window (requires X), type:
% xedt [options] [filename]
EDT+ allows both line mode and full screen editing. Full screen editing employs a keypad, which is located on the right-hand side of your keyboard. If you are in line mode when you first enter EDT+, simply type c to change to full screen mode. Once in full screen mode, you can start entering text, and your keypad is available for commands.
To return to line mode, enter <Ctrl-z>. At the prompt (*) you can type exit to exit and save, or quit which exits without saving the file updates.
Remember that when you're at the UNIX command prompt <Ctrl-z> is used as the suspend character.
Further documentation is available from the man pages, and from the vendor Boston Business Computing, Ltd.
Look under Editors on the UNIX Resources Web page for documentation on the EDT emulation package for GNU Emacs.