Invoke vi Text Editor

DESCRIPTION:
Invokes the vi editor on data and returns the edited version.

USAGE:
vi(data=<<see below>>, file=<<see below>>, editor=sys.call()[1])

OPTIONAL ARGUMENTS:
data:
any S-PLUS object.
file:
the name of the file on which the object should be written. If not given, a temporary file is created.
editor:
the name of an editor. By default the name of the function (vi) is used.

VALUE:
the edited value of the object.

SIDE EFFECTS:
NONE. It is important to realize that vi does not change data; the returned value must be assigned in order to save your editing changes, as in the first example.

DETAILS:
If errors resulted during the evaluation of the expression, the file is retained; use vi with no arguments to re-edit the file (be sure to assign the result to a name). This is typically useful if editing a function definition produced a syntax error.

You can create your own function that uses an editor of your choice by assigning the vi function to an object with the same name as your editor; see the emacs example below.

Usually functions are edited, but data may be edited also.


BACKGROUND:
The vi editor has modes of operation. The mode in which you enter vi is used to move around in the file, and to switch to other modes. There are also an insert mode and an ex mode (a command beginning with :). To get out of the insert mode, you must hit the escape key. (In some cases, it may take some experimentation to find the escape key on your keyboard.)

MOTION. The cursor keys move a line up or down, or a character left or right at a time. The h, j, k and l keys perform these tasks even if the cursor keys are not set up properly on your keyboard.

w move forward a word. b move back a word. /xxx search for xxx. (n finds next occurrence.) control-d move down half a screen. control-u move up half a screen. control-f move down a screen. control-b move up a screen. shift-G go to the end of the file. :n go to line n.

INSERTION. o open a line below and start insertion. O open a line above and start insertion. i start insertion before the character that the cursor is on. a start insertion after the character that the cursor is on.

DELETION. dd delete the line that the cursor is on. dw delete to the end of the word that the cursor is on.

SAVE AND EXIT. :w to save changes. :q to exit; these may be combined into :wq.

This is a very minimal set of commands for vi, there are many more that can speed your editing greatly. See the references or other sources for more information.


REFERENCES:
Dougherty, D. and O'Reilly, T. (1987). UNIX Text Processing. Hayden Books, Indianapolis.

Morgan, R. and McGilton, H. (1987). Introducing UNIX System V. McGraw-Hill, New York.


SEE ALSO:
data.ed , ed , fix , source .

EXAMPLES:
ttt <- vi(ttt)
ttt <- vi( ) # re-edit after a syntax error
vi(ttt) # forgot to make the assignment
ttt <- .Last.value  # assign edited version
emacs <- vi
emacs(mean) # uses emacs editor
amp;# you can save empty.fun as a blank when creating a new function:
empty.fun <- function() {}
new.fun <- vi(empty.fun)
amp;# or create a new editing function:
my.vi <- function(name=NULL)
{
        if (missing(name))
                vi( )
        else {
                name <- as.character(substitute(name))
                if (!exists(name))
                        assign(name, function() {})
                vi(get(name))
        }
}
my.vi(foo) # works even when foo is non-existent.