Shane McDonald.com : www.shanemcdonald.com
WIT Alumni Section
Site Information
Alumni Contacts
The Alumni Missing
Alumni News Section
CSD/CC Alumni Pictures
Job Information Page
WIT Course Information
CSD Alumni Members
Web Site Features on Shane McDonald.com
Articles Section
Essential Downloads
Links Directory
Search This Site
Fun, Games, Jokes and Humour
Humour and Jokes
On-Line Games
Send Free E-Cards
Other Extra Features of the site
Site Awards
Send Feedback
Make Your Startpage
Advertising
The .org Site

Articles - Internet Privacy, Webcams, Software Piracy, Cybersquatters, Basics or HTML and much more

Click Here to Print This Page.Ensure your printer is switched on, with paper in the feeder and is connected to your machine.Click Here to E-Mail a link to this page to your friend. Next Page will require your name and email as well as that of your friend.

Using Vi - A Basic Guide

Cursor Positioning

b Back one Word
w Forward one Word
f Forward one Page
b Back one Page
0 Start of line
1G start of file
$ end of line
0G end of file
XG goto line x

Inputting Text

a append after cursor
A append at end of line
i insert before cursor
I insert at start of line
o open line below
O open line above

Deleting Text

x Delete character
X Delete Character before cursor
dw Delete Word
dd Delete line
d$ Delete from cursor to end of line
d2w Delete 2 words
d5d Delete 2 lines ( could also be typed 2dd )
Changing Text
r Replace Character
cw Change Word
c5w Change 5 words
cc change line
c4l change 4 lines
R Replace / Overwrite Mode
Copying Text
To copy 7 lines

1) Put cursor on first line to be copied
2) Type
7yy
3) Position the cursor on the line before the destination
4) Type
p to paste

Moving Text
To move 7 lines

1) Put cursor on first line to be copied
2) Type
7dd
3) Position the cursor on the line before the destination
4) Type
p to paste

Misc
u Undo last change
. Redo last change
\ Escapes a control character
:set nu Display Line Numbers
G Show filename and Line Number
Patterns
/string Searches the file for the word 'string'
n Find next occurrence
N Find next occurrence Backwards
:1,$s/old_text/new_text Replaces all occurrences of the old text with new text

Also ...

Named Buffers

     In the preceding subsection, we talked about "delete buffers," which are labeled "1" through "9". Vi also let's you use "named buffers," which are labeled "a" through "z". Our old friends, the yank and pull commands, can be used to move text in and out of these buffers. You can precede and delete command (d, dd, and D) or any yank command (y, yy, and Y) with a double quote and the name of the buffer. For example:

        "aD     delete the rest of the line and put it in buffer "a"
        "c4dd   delete 4 lines, but move them to buffer "c"
        "ky3)   copy 3 sentences to the "k" buffer
        "t5yy   copy 5 lines into buffer "t"

     Pulling text from a named buffer is similar to delete buffers:

        "kp     insert contents of buffer "k" after the cursor
        "tP     insert contents of buffer "t" before the cursor

The pull commands (p and P) do not alter the contents of the named buffer. You can pull the contents again later at some other location.

Moving Text from One File to Another

     Name buffers are the correct way to move text from one file to another. The secret to this trick is that when ":e" is used to edit a new file, all of buffers (except the undo buffer) retain their information. The procedure to move text from myfile1 to myfile2 is as follows:

       1.vi myfile1
       2.yank the desired text into a named buffer
       3.:e myfile2
       4.move to the location where you want to copy the text
       5.pull the text from the named buffer

     Using Place Marks

Certain commands -- including G, /, and ? -- place an invisible mark in the buffer to keep track of where the cursor was before it was moved. You can move the cursor back to that place by typing two back-quotes:

        ``    Return to place where cursor was before an absolute move

     To try this now, type "1G" to move to the first line of this file. Then type two back-quotes to return here. This is useful  at times when you want to look at something elsewhere in the file and then return to the point where you were working. You can manually put similar invisible marks into the buffer. You name each mark with one lower-case letter for later reference.

        m Place a mark named at the cursor location
        ` Move to the mark named

     The marks are invisible, so you have to remember which one is which. Although you can have up to 26 places marked with each letter of the alphabet, it is hard to keep track of more than two or three or these.
 

To save the contents of the a buffer to filename, type
 

                            :e filename"ap (to edit a new file and put 'a's contents in it)
                            :w                     (to save it)

To save a portion of a file to another file you could type
 

                            ma                    (mark text at the top of the region to be saved)
                            mb                    (mark text at the bottom of the region to be saved)
                            :'a,'b w filename


Shane McDonald.com was Designed and Developed by Zephyr Web Design Ireland : http://www.zephyr-ireland.com/