Handout #2


VI A recap

Although more commands have been listed below than were taught in class , this is purely for your information , only the commands in bold have been discussed in class and you are expected to be conversant with them only . You can however experiment with the rest of the commands if you feel like it!


Two Modes:


1.Command Mode: Once you open a file with vi, you are in command mode. While in this

mode you can do the following:

Switch to Insert mode

Save or exit the current file you are editing

Make editing commands

Move the cursor to other positions in the file

(No text entry or editing, only commands are entered here.)


2.Insert Mode: While in insert mode, the user has the capability of entering text to the current

File. Press the ESC key to exit the insert mode and go back to command mode.






Text Input:


The following commands are used in Command mode to invoke Insert mode

[i] = inserts text before the cursor position

[I] = inserts text at the beginning of a line

[a] = append text after the cursor position

[A] = append at the end of a line

[o] = open a line below the current line

[O] = open a line above the current line


Changing Text:

[cw] = Change a word

[#cw] = change # of words

[C] = change line

[r] = replace one character

[R] = replace/type over a line

[y] = Copy or begin a yank

[p] = Paste what has been yanked

[esc key] = switches back to command






[ZZ] = Exit from visual mode, saving changes

[:x] = exit saving changes

[:wq] = write buffer, then quit

[:w] = write to buffer, (save file)

[:q] = quit out of editor

[:q!] = quit discarding changes



[^] = moves cursor to beginning of the line

[$] = moves cursor to the end of the line

[w] = move cursor one word forward

[W] = ... including any punctuation

[H] = moves cursor one character to the left

[J] = moves the cursor one character down

[K] = moves cursor one character up

[L] = moves cursor one character to the right


Changing Text

[cw] = change word

[C] = change to the end of the line

[c$] = ""



[u] = undo last change

[U] = restore current line



[/{string}] = go forward to {string}

[?{string}] = go backward to {string}



[x] = delete character at the location of the cursor

[dw] = delete word

[dd] = delete entire line

[D] = delete beginning to end of line