MTC logo MTC logo Midlands Technical College
Prospective StudentsEnrolled StudentsFaculty & StaffCommunity Partners
About
Academics
Continuing Education
Distance Learning
Student Forms
Library
Class Schedule
News & Updates
Calendar
Directory
Site Map
Ask MTC
MTC Jobs Bookstore
Home
navigation
 
Search

 

About MTC Academics Continuing Education Distance Learning Student Forms Library Class Schedule News & Updates Calendar Directory Site Map Ask MTC MTC Jobs Bookstore Home


CPT 247


Quick Reference

Exercise

Shellscript1

 

Buffers and More Buffers

The editor vi actually works on a copy of the file in the work buffer. While using the vi editor, one has access to other buffers as well. There are 36 buffers available to you.

  •     unnamed buffer
  •     named buffers "a, "b, "c, "d, ....., "x, "y, "z
  •     numbered buffers "1, "2, "3", "4, ......., "8,"9

The unnamed buffer is sometimes called the general-purpose buffer. When you change or delete text, the old text is not discarded immediately. Instead, vi moves the old material into the unnamed buffer, and hold the text there until you change or delete more material. This would allow you to "undo" or restore the text you have deleted using the "undo" command: u

This puts the old text back where it came from. Since vi has only one unnamed buffer, the undo command can only restore the most recent change you made. The previous changes are lost forever.

The named buffers and numbered buffers are useful for moving blocks of text around a file or between different files.

The following scenario would move 4 lines from file named myfile5 to myfile6.

vi myfile5 myfile5

( in several lines in myfile5)

"a4yy        (yank 4 lines and place them in the buffer named a)

:n              ( vi the next file)

"ap           (place the lines in the named buffer a at the current cursor position)

If you try the Put command on a buffer that has nothing in it, the computer will respond with an error message such as

    Nothing in register a

Buffers are also known as registers.

The contents of the named buffer are not changed by the Put command. One can put the same 4 lines into the file again if so desired.

Second scenario: Moving text between files.

1. vi fileA

2. move the cursor to the first of the lines you want to trasnfer.

3. yank the lines into a named buffer named "m.

        "m4yy

4. enter the edit file command. Type :e followed by the name of the file that is to receive the yanked text. If the file is named mystuff, type

        :e mystuff   

5. put the lines.

        "mp

6. write the lines to the file.