Guest

Cisco PGW 2200 Softswitch

Using Vi to Work With the Cisco PGW 2200 PSTN Gateway

Document ID: 27718



Contents

Introduction
Prerequisites
      Requirements
      Components Used
      Conventions
Vi Editor
      Before You Begin to Use Vi
      The Vi Modes
      Start and Exit Vi
      Session Customizing Commands
      Cursor Motion
      Search for Text or Characters
      Regular Expressions
      Delete and Replace Text
Operating System Commands
      Compare-Find-Link Files
      Compress and Extract Files
NetPro Discussion Forums - Featured Conversations
Related Information

Introduction

This document provides you with commands to better use the standard text editor, called the Vi editor (pronounced "vee eye" editor), that is integrated in the Sun Microsystems Solaris Operating Environment. This document describes how to edit the XECfgParm.dat configuration file of the Cisco Media Gateway Controller (MGC) software application, and how to use the general system commands from the Sun Solaris Operating Environment in order to maintain and view information. This document also discusses how to set up Vi, the problems with the appearance of the terminal screen, how to create and modify new and existing files, the difference between the different Vi modes and shortcuts related to the work with these modes. The general system commands focus on file handling, compression, user privileges and permissions to files.

Prerequisites

Requirements

Cisco recommends that you have knowledge of these topics:

  • Basic Solaris administration tasks and commands

  • Cisco MGC Software

Components Used

The information in this document is based on these software and hardware versions:

  • Sun Microsystems, Solaris 2.6, 2.8

  • Cisco MGC Software Release 7.4(x), 9.x.(x)

The information in this document was created from the devices in a specific lab environment. All of the devices used in this document started with a cleared (default) configuration. If your network is live, make sure that you understand the potential impact of any command.

Conventions

Refer to Cisco Technical Tips Conventions for more information on document conventions.

Vi Editor

The Vi editor is a full-screen, character-based editor that you can use to create and modify ASCII text files that:

  • Customize your work environment

  • Change configuration files from applications that run on the systems

  • Write script files for automated tasks

Bill Joy wrote this program in 1976. The program is universally available with Unix-based systems. Vi is a powerful and flexible editor, and is organized in a logical fashion. Vi is different from other editors or word processors, which makes Vi tricky to learn because of the various options. Vi is case-sensitive, and you cannot use Vi along with a mouse-pointing device to position the cursor. Vi does not have formatting capabilities. The Vi editor puts files in the memory buffer of the system so the files can be written to disk or be discarded directly from the buffer.

Before You Begin to Use Vi

If you notice a jumpy, scrolling behavior in the screen after the appearance of a file you opened with Vi, a problem exists with the system's terminfo or termcap information for your terminal. If the selected terminfo/termcap entry does not have the correct scrolling capabilities, these behaviors can come up. In such a case, you must specify the Vi editor a different terminal to use.

In order to set the terminal correctly, you must know which shell is currently in use. Issue the echo $shell command to find out which shell is currently in use. In this example, the terminal is vt100. Check the /etc/termcap file in the file system of your workstation in order to determine which terminal is supported. Reset your terminal with the tset command, and you are all set to use Vi properly.

Shell

Command

C Shell (/bin/csh)

Set term = vt100

Bourne Shell (/bin/sh) or Korne Shell (/bin/ksh)

Export TERM

TERM = vt100

The Vi Modes

All commands available with Vi can be classified in one of the three modes:

  • Command mode

    The Command mode is the default mode when you start Vi to create and edit files, to position the cursor, and to modify existing ASCII files. All commands are initiated from this mode. Press the ESC key to return to the Command mode.

  • Entry mode

    The Entry (or input) mode enables you to enter new text. Use an Insert or Append command to go from the Command mode to the Entry mode.

    This table demonstrates different Insert and Append commands that you can use in the Entry mode.

    Description

    Shortcut

    Insert before cursor or before line

    i, I

    Append after cursor or after line

    a, A

    Replace one character or many characters

    r, R

    Open new line after or line before

    o, O

    The Entry commands are entered by themselves without pressing the ENTER key. If you use the "vedit filename"or the ":set showmode" parameter after you start Vi, you can see the type of Entry mode (Insert or Append) in which you are, in the lower-right corner. If you are not in Entry mode, you do not see a mode after you do this. If you want to change from Insert to Append mode, go back into the Command mode and into the appropriate Entry mode.

  • Last-line mode

    The Last-line mode enables you to save your work and quit Vi. Type a colon to get to this mode. Press the ENTER key to return to Command mode.

    This table shows you a comprehensive collection to move between Vi modes.

    From Mode

    To Mode

    Command/Key

    Command

    Entry

    Insert or Append command

    Entry

    Command

    Escape

    Command

    Last Line

    Colon

    Last-line

    Command

    Enter

    Entry

    Last Line

    Escape + Colon

    Last-line

    Entry

    Escape + Insert or Append command

Start and Exit Vi

To start the Vi editor, issue the vi or vi filename command. With the first method, you will have to specify a filename to save your work. With the second method, you can open and modify existing files.

Save your work periodically with the :w command (write command), or specify a filename behind this command.

In order to exit the Vi editor, type "ZZ" and press ENTER, which is equivalent to the :wq! command. The "!" overrides read-only permissions if you are the owner of the file (see the Permissions section). This exits Vi and saves your changes from the buffer to the file on disk. In order to abandon the program, but you do not want to save any changes, go into Command mode and issue the :q! command. If you want to discard all of your changes from the beginning of the last write and reedit the file, issue the :e! command from Last-line mode. If the Vi editor crashes, you can recover the last session with the vi –r filename command.

The Vi help pages in Unix (man vi) do not contain descriptions of the commands. This is because the Vi editor is part of the ex family of editors. Vi is screen-oriented and the ex editor, with its own set of commands, is line-oriented, and you can use it while in Vi. All the Last-line commands in this document are actually ex editor commands and you must use the ex pages in Unix (man ex) to find the Last-line commands.

Session Customizing Commands

The Vi editor includes options to customize your edit sessions. This table lists such commands, which are ex editor set commands used from Last-line mode to control the specific function.

Function

Command

Show line number

:set nu

Hide line number

:set nonu

Display current mode of operation (turned on automatically if vedit is used)

:set showmode

Turn off mode display

:set noshowmode

Display all variables

:set

Display all possible Vi variable and their current setting

:set all

To automatically enable Vi options when you enter Vi, create a file in the home directory, and name it .exrc (ex editor run control). This file contains the set options without the colon in front of them (one command per line). This file is read every time you start a new Vi session.

Cursor Motion

You can use the cursor positioning commands in the Command mode when there is existing text and you want to move around in this text. On most workstations, you can use the cursor control keys, but if you are unable to do so, you can find additional commands in this table to move the cursor:

Description

Shortcut

Left, down, up, right

h, j, k, l, cursor keys

Next word, blank delimited word

w, W

Beginning of word, of blank delimited word

b, B

End of word, of blank delimited word

e, E

Beginning, end of line

0, $

Moving a screen at a time forward, backward

[Ctrl] f, [Ctrl] b

Moving a half screen at a time forward, backward

[Ctrl] d, [Ctrl] u

Beginning of next line

Return

Moving one character right (forward)

Space

Again, the Vi is case-sensitive, so ensure you use the correct shortcut.

Search for Text or Characters

The commands in this table allow for advanced editing such as, to find a line or conduct search-and-replace functions:

Description

Shortcut

Search forward

/string

Search backward

?string

Repeat search in same/ reverse direction

n, N

Goes to last line of file

G

Goes to line x

:x

Note: The / and ? are Last-line commands, but they do not require a colon first.

Regular Expressions

Use the regular expressions in this table to define a range of parameters and variables that you can use to have more granularity by using them together with specific functions (such as, search and replace).

Description

Shortcut

Any single character except newline

. (dot)

Zero or more repeats

*

Any character in set, not in set

[…], [^…]

Beginning, end of line

^, $

Beginning , end of word

\<, \>

Delete and Replace Text

Use the commands in this section in the Command mode. While in the Command mode, position the cursor where you want the cursor to be, and use the commands in this table to delete or replace the text:

Description

Shortcut

To end of line

d

Line

dd

Character to right, left

x, X

Replace current character

r

Change contents of current line

cc

Change contents of current word (type new word and press ESC)

cw

Cut and Paste

DD then p

Copy and Paste

yy then p

Undoes all changes that you have made to the current line

U

Note: These commands are case-sensitive and entered without the ENTER key.

Operating System Commands

This section of the document lists commands that are useful to change the permission of files, compress files for transportation, and compare files to see differences in content.

Files and directories in your file system have certain access levels for the owner, group, and others who use the files. You can define a very high granularity to access files in a Unix environment. Here is an example output of the ls -1 command at the prompt:

#ls -1
drwxr-xr-x 2 root sys 512 Aug 6 09:30 mnt

This table helps you read the characters of the output from left to right (drwxr-xr-x):

Set

Meaning

First Character

Determines if the item is a directory (d), a file (-), or a link (l).

Second, third, and fourth characters

This set shows the permissions that have been set for the item's "owner."

Fifth, sixth, and seventh characters

This set shows the permissions that have been set for the "group."

Eight, ninth, and tenth characters

This set shows the permissions that have been set for "other."

The next table shows the permissions that you can grant or remove from the files or directories. The symbols in this table are used in the syntax command of the chmod ugo+/-rwx filename command in order to change permissions.

Symbol

Meaning

u

user

g

group

o

other

other

All

r

Read

w

Write

x

Execute

+

Add permission

-

Take away permission

Compare-Find-Link Files

Use these commands to locate differences in files, find a specific file in a directory, and use a virtual link in the directory structure:

  • diff filename1 filename2 —Displays differences in both files.

  • find directory –name filename –print—Looks for a specific file in a specific directory.

  • ln -s folks /auto/People/—For easier navigation through the file system and directory structure, use a virtual link from anywhere in the directory structure. To use this link, type "cd folks."

Compress and Extract Files

You can compress files for backup and transport to different locations. In order to compress files on a system where the MGC software is installed, use one of the programs from this table:

Program

Compress

Extract

Tar

tar -cvf newfile.tar directory/

tar xvf filename.tar

Gzip

Gzip filename

gunzip filename

Uuencode

uuencode filename > filename.uu

uuencode filename.uu

Note: You need to know the differences in functionality between these programs before you use them.

NetPro Discussion Forums - Featured Conversations

Networking Professionals Connection is a forum for networking professionals to share questions, suggestions, and information about networking solutions, products, and technologies. The featured links are some of the most recent conversations available in this technology.
NetPro Discussion Forums - Featured Conversations for Voice
Service Providers: Voice over IP
Voice & Video: Voice over IP
Voice & Video: IP Telephony
Voice & Video: IP Phone Services for End Users
Voice & Video: Unified Communications
Voice & Video: IP Phone Services for Developers
Voice & Video: General

Related Information



Updated: Jan 31, 2006Document ID: 27718