Monday, 3 March 2008

VI Tutorial Part II

We have been through VI with a small tutorial part I link is here

Part II of this VI Tutorial goes h3r3

V. Deleting, Copying and Changing

The next three operations we will discuss will be deleting, copying, and changing. These three will be discussed together because the methods of describing the text that these commands operate on is identical.

There are well over 30 different ways that you can tell VI to move the cursor to a new location in the document. These movements can also be used to describe sections of the document that you wish to perform the delete, copy or change operation on. Typically, you will type a single keystroke which describes the type of operation you wish to perform, (e.g. 'd' to delete), then you type the cursor movement command that will tell vi on which piece of text you would like that operation to work. For example, if 'w' moves one word forward, 'dw' will delete a word, while 'cw' will change a word.

These editing commands are outlined below:


d

Delete text. (see explanation above)

y

Copy text (that is, yank it into a holding area for later use). (see explanation above)

c

Change text from one thing to another, which you will type. (see explanation above)

!

Filter text through a program.

<

Shift a region of text to the left.

>

Shift a region of text to the right.

In addition to the functions described above, each of these keystrokes when doubled become editing commands which operate on entire lines. For example, '3dd' deletes the next three lines including the current line, while '2yy' yanks a copy of the next two lines including the current line into a paste buffer.


VI. Single Key Movements

Following one of the commands identifying keystrokes listed in Figure 1 above, you must tell VI on which portion of the document to perform the operation. This is done by typing a keystroke that indicates a movement command. Most of these are outlined below. The more complicated movements will be described later on.

h

Move cursor to the left one character.

l

Move cursor to the right one character.

j

Move cursor down one line.

k

Move cursor up one line.

^

Move cursor to the beginning of the line.

$

Move cursor to the end of the current line.

1G

Move cursor to the first line of your document. Other numbers will move to the line specified by number (ex. '50G' goes to the 50th line).

G

Move cursor to the last line of your file.

CTRL U

Move cursor up in file 12 lines. Hold down the key marked CTRL (stands for "control") and type 'U'. CTRL is like another shift key.

CTRL D

Move cursor down in file 15 lines.

w

Move cursor forward to the next word, stopping at punctuation.

W

Move cursor forward to the next word, ignoring punctuation.

e

Move cursor forward to the end of the word, stopping at punctuation.

E

Move cursor forward to the end of the word, ignores punctuation.

b

Move cursor backwards to the previous word, stopping at punctuation.

B

Move cursor backwards to the previous word, ignores punctuation.

H

Move cursor to the top line of the screen, (as opposed to the top of the document which may not be the same place).

M

Move cursor to the middle of the screen.

L

Move cursor to the last line on the screen.

%

Move cursor to the matching parenthesis, bracket or brace. Great for debugging programs.

(

Move cursor to the beginning of the previous sentence (where a punctuation mark and two spaces define a sentence).

)

Move cursor to the beginning of the next sentence.

{

Move cursor to the beginning of the current paragraph.

}

Move cursor to the beginning of the next paragraph.

;

Repeat the last f or F command (see below).

Almost Single Key Movements

The following key movements use additional information or input. That is, although they are single key movements their correct operation depends on what came before or what follows.

'

Move cursor to a previously marked location in the file. (ex. ma marks the location with the letter 'a', so 'a (apostrophe 'a') moves back to that location).

f

Find the character corresponding to the next keystroke typed. Move the cursor to the next occurrence of that character (on the current line only).

F

Same as 'f' but movement is backwards.

You probably will not adopt the immediate use of all of these movements, but it is possible to gain proficiency in their use only by using them.

No comments:

FEEDJIT Live Traffic Feed