CHAPTER 5: EDITORS
back to the Computing Guide Contents


Two editors are available on MMM's workstations, vi, the standard Unix editor, and GNU Xemacs, commonly called Xemacs, a public-domain software package widely available on a number of platforms. Both are used for editing ASCII files; they cannot edit binary or special files such as FrameMaker files.

There are benefits to learning both of these editors. Xemacs, a powerful screen editor, provides more flexibility, but is not available by default on all Unix platforms. Since vi is available with all Unix workstations, it is important to learn at least the basic commands for editing a file in vi. This chapter provides basic information on both editors.


5.1 The vi Editor 

The vi editor has two modes, passive and active. In passive mode, you can move the cursor and delete text, and in active mode you can insert and move text. When you first enter vi, you are in passive mode. Entering any one of the active-mode commands will put you in active mode. To return to passive mode, press the ESC key. You must return to passive mode after inserting text in order to move the cursor somewhere else in the file.

5.1.1 Entering vi

To start a vi editing session, enter
        vi filename

5.1.2 vi Commands

The following two lists describe some of the passive-mode cursor and active-mode vi commands. Note that the case of the command (uppercase or lowercase letters) is important. Any command preceded by an "n" means you can enter a number to perform the command n number of times.

Passive-Mode Commands

arrow keys      Moves the cursor right, left, up, or down.

              Moves to the end of line.

^               Moves to the beginning of line.

              Moves cursor to top of screen.

L               Moves cursor to bottom of screen.

nCTRL-f         Scrolls file forward one screen.

nCTRL-b         Scrolls file backward one screen.

w               Moves forward one word.

              Moves backward one word.

nG              Moves to line number n.

/string         Searches forward for string.

?string         Searches backward for string.

nx              Deletes character(s) at cursor.

ndd             Deletes current line(s).

Active-Mode Commands

              Inserts text before the cursor.

              Appends text after the cursor.

              Inserts text after the current line.

              Appends text before the current line.

              Opens blank line after current line.

O               Opens blank line before current line.

ESC             Terminates input mode.

5.1.3 Exiting vi

To exit vi, you can enter either of the following commands in passive mode:
:q!             Exit without saving changes.
ZZ              Exit saving all changes 

:w!             Write the file to a file of a different 
                name before exiting.

5.1.4 Other Useful vi Features

File Recovery

If you lose your connection to a workstation during a vi session, recover file changes with the -r option.
        vi -r filename

Removal of Trailing Blanks

To remove trailing blanks in vi, execute the following while in passive mode.
:set list       This command shows what has happened.
:%s/ *$//       This command trims lines. 
                The spaces are important.

Online Information



Return to top of page

5.2 The Xemacs Editor


The public-domain GNU Xemacs editor, was developed at MIT to run on Unix systems. Xemacs  is a powerful editor that provides the capability to customize the user environment by programming the keypad and various other keyboard keys. Since different sites will program their keyboards to meet their specific requirements, it is recommended that users learn the generic Xemacs commands as these will be common among various Unix platforms. Users may set up their own key bindings if they want, however, these will not be supported by the systems group.  This section will describe some of these basic commands. In addition, a quick reference guide to all the Xemacs commands can be obtained from the division documentation library.

To use the custom key bindings for the MMM environment, copy the file /usr/local/skel/.xemacs into your login directory.

Please note the following conventions used in the control sequences given throughout this chapter.

C-  Press the CTRL key along with the letter indicated.

M-  Press the ESC key along with the letter indicated. 
    (The ESC key may be the F11 key on some DEC keyboards, 
    rather than the key marked ESC.)

5.2.1 Entering and Exiting Xemacs

Entering Xemacs: Two Methods

1.      To enter Xemacs and go directly into a specific file, type

        xemacs filename

        If the file name you enter does not exist in your directory,
        Xemacs will automatically create a new file.

        Alternatively, if you are not working on an X Windows device, you can enter

        xemacs -nw filename OR   2.      To enter Xemacs without specifying a file name, simply type         xemacs         You are placed into a generic "scratch" file. At this point,          you can read a file into Xemacs by entering C-x C-f.          At the prompt, enter the name of the file.

Exiting Xemacs: Two Methods

1.      To temporarily suspend Xemacs, press

        C-z

        This will temporarily exit you from the file you were editing, 
        and put your editing session into Unix background mode, so that 
        you can execute Unix shell commands. To resume your editing session, 
        type the Unix command, fg at the prompt. You will then be 
        placed back in the file at the point where you were editing when 
        you entered C-z.

2.      To permanently exit Xemacs, enter 

        C-x C-c

        You will then be prompted to save changes made in the current file 
        and any other Xemacs files you may have been editing.

5.2.2 On-Line Help in Xemacs

Xemacs features an extensive on-line help facility. To access Xemacs help, enter C-h. For first-time users, there is also an on-line tutorial, which can be accessed by entering C-h t. Following are some additional commands for obtaining help within Xemacs.
        C-h b   Get current key bindings. 
        C-x 1   Get rid of Help window. 
        M-C-v   Scroll through help window. 
        C-h a   Apropos; show commands matching a string.
        C-x k   Return from tutorial to original file.
        C-x b   Return from tutorial (buffer) to original file (buffer).

5.2.3 Editing Commands

Following are some of the basic commands for editing an ASCII file in Xemacs:
        C-s     Search forward.

        C-r     Search backward.

        C-a     Go to beginning of line. 

        C-e     Go to end of line. 

        M-<     Go to beginning of buffer. 

        M->     Go to end of buffer. 

        C-v     Scroll to next screen. 

        M-v     Scroll to previous screen. 

        C-d     Delete a character. 

        M-d     Kill a word. 

        C-k     Kill to end of line. 

        C-y     Yank back last thing killed. 

        M-%     Interactively replace a text string. 

        SPC     Replace this one, and go on to next. 

        DEL     Skip to next without replacing. 

              Replace all remaining matches.
By default, Xemacs functions in insert mode. To enter overwrite mode, type M-x overwrite-mode. Thereafter, type this command to toggle back and forth between the two modes.

5.2.4 Multiple Windows

Several options for using multiple windows within Xemacs are listed below.
        C-x 5   Split screen into two horizontal windows.

        C-x 2   Split screen into two vertical windows.

        C-x o   Switch between windows. 
        C-M-v   Scroll through other window. 
        C-x 0   Delete current window.         
        C-x 1   Delete other window.

5.2.5 Creating Keyboard Macros

For repetitive editing, create keyboard macros within Xemacs. To start defining a macro, enter C-x. All the keystrokes you enter after this point will be remembered. To end the macro definition, enter C-x. To execute all commands previously entered between the C-x commands, enter C-x e.

5.2.6 Xemacs Directory Editing

Xemacs also features a useful directory-editing capability. To access the directory-editing utility, enter
        xemacs
You are placed in a blank Xemacs "scratch" file. Once in this file, enter
        M-x dired
The name of your current directory appears at the bottom of the screen. To edit this directory, press RETURN. To edit a different directory, backspace and type the name of the desired directory, then press RETURN. A listing of the files in the specified directory appears.

You can now move through this list using the arrow keys. The following commands are available.

n  Move down to the next file (the down-arrow key works as well).
        
p  Move up to the previous file (the up-arrow key works as well).

d  Flag file on this line for deletion. (A "D" will appear next
   to the file.) To actually delete the flagged files, use the x 
   command.

u  Remove deletion flag for file on this line. 
        
#  Flag all auto-save files (files that start and end with #) 
   for deletion.
        
~  Flag all backup files (files that end with ~) for deletion.

x  Delete files that are flagged for deletion. (This command 
   first lists all the files that are marked for deletion and asks you 
   whether you want to delete them.)
        
c  Copy file on current line. (You must supply a new file name.)

r  Rename file on current line. (You must supply a new file
   name.)

v  Visit file on current line. (You can move around in the file,
   but you cannot change it.) 
        
o  View file on current line in another window.

On-Line Information

Hardcopy References



Return to top of page

Copyright © UCAR 1998 - Disclaimer - mmminfo@ncar.ucar.edu
Last Modified: 1 December 2002