Online
 
Thursday, 20 November 2008
 
 

VI Editor Closing Files | Print |  E-Mail
 
You can use vi to edit any text file. vi copies the file to be edited into a buffer (an area temporarily set aside in memory), displays the buffer (though you can see only one screenful at a time), and lets you add, delete, and change text. When you save your edits, vi copies the edited buffer back into a permanent file, replacing the old
file of the same name. Remember that you are always working on a copy of your file in the buffer, and that your edits will not affect your original file until you save the buffer. Saving your edits is also called "writing the buffer," or more commonly, "writing your file." vi is the UNIX command that invokes the vi editor for an
existing file or for a brand new file. The syntax for the vi command
is:

$    vi     [filename    ]

The brackets shown on the above command line indicate that the
filename is optional. The brackets should not be typed. The $ is the
UNIX prompt. If the filename is omitted, vi will open an unnamed
buffer. You can assign the name when you write the buffer into a
file. For right now, though, let's stick to naming the file on the
command line.
 



A filename must be unique inside its directory. On older System V
UNIX systems, it cannot exceed 14 characters in length (most
common UNIX systems allow much longer names). A filename can
include any 8-bit character except a slash (/), which is reserved as
the separator between files and directories in a pathname, and
ASCII NUL, the character with all zero bits. You can even include
spaces in a filename by typing a backslash (\) before the space. In
practice, though, filenames generally consist of any combination of
uppercase and lowercase letters, numbers, and the characters dot
(.) and underscore (_). Remember that UNIX is case-sensitive:
lowercase letters are distinct from uppercase letters. Also remember
that you must press RETURN to tell UNIX that you are finished
issuing your command.

When you want to open a new file in a directory, give a new
filename with the vi command. For example, if you want to open a
new file called practice in the current directory, you would enter:

$    vi practice

Since this is a new file, the buffer is empty and the screen appears
as follows:

~
~
~
"practice" [New file].

The tildes (~) down the left-hand column of the screen indicate that
there is no text in the file, not even blank lines. The prompt line
(also called the status line) at the bottom of the screen echoes the
name and status of the file.

You can also edit any existing text file in a directory by specifying
its filename. Suppose that there is a UNIX file with the pathname
/home/john/letter. If you are already in the /home/john directory,
use the relative pathname. For example:

$    vi letter

brings a copy of the file letter to the screen.

If you are in another directory, give the full pathname to begin
editing:

$    vi /home/john/letter
Users' Comments (0)

Comment an article
  Name
  E-mail
   Title
Available characters: 4000
 Notify me of follow-up comments
This image contains a scrambled text, it is using a combination of colors, font size, background, angle in order to disallow computer to automate reading. You will have to reproduce it to post on my homepage
Enter what you see:

No comment posted

Jumbo Coklat
 
Top! Top!