=head1 NAME

VI - VI module within perl embedded nvi


    sub wc {
      my $words;
      $i = $VI::StartLine;
      while ($i <= $VI::StopLine) {
	$_ = $curscr->GetLine($i++);
      $curscr->Msg("$words words");


This pseudo module is available to perl programs run from within nvi and
provides access to the files being edited and some internal data.

Beware that you should not use this module from within a C<perldo> or
from within an C<END> block or a C<DESTROY> method.

=head2 Variables

These are set by nvi before starting each perl command.

=over 8

=item * $curscr

Object that represents the current screen.
It can be used as the ScreenId parameter of the functions below,
or you can use object oriented syntax.

	# the following two are equivalent
	VI::DelLine($curscr, 57);

=item * $StartLine

Line number of the first line of the selected range or of the file if no
range was specified.

=item * $StopLine

Line number of the last line of the selected range or of the file if no
range was specified.


=head2 Functions

=over 8

=item * AppendLine


Append the string text after the line in lineNumber.

=item * DelLine


Delete lineNum.

=item * EndScreen


End a screen.

=item * FindScreen


Return the screen id associated with file name.

=item * GetCursor

    ($line, $column) = VI::GetCursor(screenId);

Return the current cursor position as a list with two elements.

=item * GetLine


Return lineNumber.

=item * GetMark

    ($line, $column) = VI::GetMark(screenId,mark);

Return the mark's cursor position as a list with two elements.

=item * GetOpt


Return the value of an option.

=item * InsertLine


Insert the string text before the line in lineNumber.

=item * LastLine


Return the last line in the screen.

=item * MapKey


Associate a key with a perl procedure.

=item * Msg


Set the message line to text.

=item * NewScreen


Create a new screen.  If a filename is specified then the screen is
opened with that file.

=item * Run


Run the ex command cmd.

=item * SetCursor


Set the cursor to the line and column numbers supplied.

=item * SetLine


Set lineNumber to the text supplied.

=item * SetMark


Set the mark to the line and column numbers supplied.

=item * SetOpt


Set an option.

=item * SwitchScreen


Change the current focus to screen.

=item * TagQ

    $screen->TagQ("tag identification string")

Creates a new tag queue object associated to $screen
to which "tags" can be added.
See further about methods you can use on tag queues.

=item * UnmapKey


Unmap a key.

=item * Warn

This is the default warning handler.
It adds any warnings to the error string.

=item * Opt


Returns a tied hash representing the options of the screen.
Note that you can only retrieve and set hash elements.

=item * Map


Returns a tied hash representing the mappings of the screen.
Note that you can only retrieve, set and delete hash elements.

=item * Mark


Returns a tied hash representing the marks of the screen.

=item * Line


Returns a tied array representing the lines of the screen.


=head2 Tag queue methods

=item * Add

    $tagq->Add($filename, $searchstring, $msg)

Adds a tag to the tag queue. 
The $searchstring argument is (line)number or
a string representing a regular expression.

=item * Push


Pushes the tag queue onto its associated screen.
The result of the operation is as if the user had enter the
tag command and nvi had found the locations that were added
using the Add method.

For an example, see the script.



    sub showmarks {
      my ($mark, $all);
      for $mark ('a' .. 'z') {
        eval {VI::GetMark($VI::ScreenId, $mark)};
        $all .= $mark unless ($@);
      VI::Msg($VI::ScreenId,"Set marks: $all");

    sub forall {
      my ($code) = shift;
      my ($i) = $VI::StartLine-1;
      while (++$i <= $VI::StopLine) {
        $_ = VI::GetLine($VI::ScreenId, $i);
        VI::SetLine($VI::ScreenId, $i, $_) if(&$code);

Now you can do

    :perl forall sub{s/perlre/substitution/}

Although you'll probably use

    :perldo s/perlre/substitution/


See L<perlre> for perl regular expressions.

=head1 SEE ALSO


=head1 AUTHOR

Sven Verdoolaege <>