Before doing anything to a document, type the following command followed by a carriage 
return :set showmode

A GOOD PRACTICE ESPECIALLY FOR BEGINNERS: WHEN USING VI, HIT [ESC] TWICE BEFORE 
EVERY NEW COMMAND. THIS MAKES SURE YOU AREN'T IN THE WRONG MODE.

When you open VI, you can't just start typing a thesis because VI has different modes 
such as APPEND MODE, INSERT MODE, REPLACE MODE, and COMMAND MODE. So to do certain 
actions, you must first enter the appropriate mode. See "MODES" for more in-depth 
information.

The final page of this document is a list of VI core commands. These are the bare 
essentials of VI compressed onto one page.

STARTING VI    (VI is Case Sensitive!!! So make sure Caps Lock is OFF.)

COMMAND			RESULT 

vi filename 		Edits filename.
vi -r filename		Edits last saved version of filename after a crash.
vi + n filename		Edits filename and places the cursor at line n.
vi + filename		Edits filename and places cursor on the last line.
vi filename  file2 ... 	Edits filename and then edits file2 and so on. After saving 
				file1 enter :n for the next file.
vi +/string file 		Edits file and places cursor at the first line containing 
				string.

ENDING VI     (Saving, exiting, etc.)

COMMAND			RESULT 

ZZ or :wq or :x		Saves and exits VI.
:w				Saves current file but does not exit.
:w file 			Saves current as file but does not exit.
:w! file 			Saves file overriding normal checking.
:n,mw file 			Saves lines n through m to a file named file.
:n,mw>>file 		Appends lines n through m to the end of a file named file.
:q				Quits VI, saving changes before leaving. (You may be 
				prompted to save.)
:q!				Quits VI without saving changes.
Q				Escapes VI into ex editor with the same file; :vi returns.
:e!				Re-edits current file disregarding changes since last save.
:we!				Re-edits current file saving changes. 


STATUS     (Line numbers, etc.)

COMMAND			RESULT 

:.=				Shows current line number.
:=				Shows number of lines in file.
CTRL-g			Shows filename, current line number, total lines in file, 
				and % of file location.
:l  (letter "l")		Displays tab (^l) backslash (\) backspace (^H) newline 
				($) bell (^G) formfeed (^L^) of current line.

MOVING     (These will tell you how to get the cursor where you want itöfast.)

MOVING THE CURSOR

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode. 
arrow keys			These do work, but they may be too slow on big files.
h j k l			Left, down, up, and right, respectively.
CTRL-d			Moves forward ¸ screenful.
CTRL-f			Moves forward one entire screenful.
CTRL-u			Moves backward ¸ screenful.
CTRL-b			Moves backward one entire screenful.
nG				Moves to line n in the file.
G				Moves to the end of file.
H				Moves to the top of the screen.
nH				Moves to line n from the top of the screen.
M				Moves to the middle of the screen.
L				Moves to the bottom of the screen.
nL				Moves to line n from the bottom of the screen.
w or W			Moves to the start of the next word in the line; W ignores 
				punctuation.
b or B			Moves to the start of the previous word in the line; B 
				ignores punctuation.
e or E			Moves to the end of the next word in the line; E ignores 
				punctuation.
0 (zero) or |		Moves to the first column in the current line.
n|				Moves to the column n in the current line.
^				Moves to the first non-blank character in the current line.
$				Moves to the last character in the current line.
+ or 			Moves to the first character in the next line.
-				Moves to the first non-blank character in the previous line.
(				Moves back to the beginning of sentence.
)				Moves forward to the beginning of the next sentence.
{				Moves back to the beginning of the paragraph.
}				Moves forward to the beginning of the next paragraph.


MOVING     (These will tell you how to get the cursor where you want itöfast.)

MOVING THE SCREEN

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode.
CTRLöe			Moves screen up one line.
CTRLöy			Moves screen down one line.
CTRLöu			Moves screen up ¸ page.
CTRLöd			Moves screen down ¸ page.
CTRLöb			Moves screen up one page.
CTRLöf			Moves screen down one page.
CTRLöI			Redraws screen.
z 			zöcarriage return makes the current line the top line on 
				the page.
nz 			Makes the line n the top line on the page.
z.				Makes the current line the middle line on the page.
nz.				Makes the line n the middle line on the page.
zö				Makes the current line the bottom line on the page.
nzö				Makes the line n the bottom line on the page.


MODES     (Adding and/or replacing text)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode.
itext ESC			Insert mode÷Start typing and it will insert text before 
				the letter your cursor currently highlights until ESC 
				is used.
Itext ESC			Insert mode÷Same as (i) except it will insert text before 
				the first nonblank character on the line until ESC is used.
atext ESC			Append mode÷Allows you to insert text after the letter your 
				cursor currently highlights until ESC is used.
Atext ESC			Append mode÷Same as (a) except it will insert text at the 
				end of the line until ESC is used.
rchar ESC			Replace mode÷Replaces the currently highlighted character 
				with char until ESC is used.
Rtext ESC			Replace mode÷Same as (r) except it will overwrite until 
				ESC is used.
o				Opens new line below the current line and insert until 
				ESC is used.
O (letter "O")		Opens new line above the current line and insert until 
				ESC is used.
CTRLöv char 		While inserting, ignores special meaning of char (e.g., 
				for inserting characters like ESC and CTRL) until ESC is 
				used.
:r file 			Reads file and inserts it after current line.
:nr file 			Reads file and inserts it after line number n.


SEARCHING     (Find and/or replace what you need)

CHARACTERS			WHAT THEY MATCH...

^ (caret)			Matches beginning of line.
$				Matches end of line.
.				Matches any single character.
\<				Matches beginning of word.
\>				Matches end of word.
[str]				Matches any single character in str.
[^str]			Matches any character not in str.
[a-n]				Matches any character between a and n.
*				Matches zero or more occurrences of previous character 
				in expression.
\				Escapes the meaning of the next character (e.g., \$ allows 
				you to search for $).
\\				Escapes the \ character.

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode.
%				Searches to beginning of balancing ( ) [ ] or { }.
fchar 			Searches forward in current line to char.
Fchar 			Searches backward in current line to char. 
tchar 			Searches forward in current line to character before char.
Tchar 			Searches backward in current line to character before char.
/str 			Finds forward to str.
?str  			Finds in reverse for str.
:set ic			Ignores case when searching.
:set noic			Pays attention to case when searching.
:n,ms/str1/str2/opt 	Searches from n to m for str1; replaces str1 to str2; using 
				optöopt can be g for global change, c to confirm change 
				(y to acknowledge,  to suppress), and p to print changed 
				lines.
&				Repeats last :s command.
:g/str/cmd			Runs cmd on all lines that contain str.
:g/str1/s/str2/str3/	Finds the line containing str1, replaces str2 with str3.
:v/str/cmd 			Executes cmd on all lines that do not match str.


EDITING     (Deleting, copying, placing text, joining lines, changing text, 
		repeat command, undo command)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode. 
CTRLöh      		or 
Backspace			While inserting, deletes previous character.
CTRLöw			While inserting, deletes previous word
CTRLöx			While inserting, deletes to start of inserted text.
nx				Deletes n characters starting with current; omitting n 
				deletes current character only.


EDITING  	(Deleting, copying, placing text, joining lines, changing text, repeat 
		command, undo command)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode. 
nX				Deletes previous n characters; omitting n deletes previous
				character only.
xp				Switches character at cursor with following character.
ndw				Deletes the next n words starting with current; omitting n 
				deletes the current word only.
ndb				Deletes the previous n words starting with current; omitting 
				n deletes the previous word only.
ndd				Deletes n lines beginning with the current line; omitting n 
				deletes the current line only.
:n,md				Deletes lines n through m.
D or d$			Deletes from the cursor to the end of the line.
dcursor_cmd 		Deletes everything included in the cursor command (e.g., dG 
				would delete from current position to the end of the file, 
				and d4 would delete to the end of the fourth sentence).
nyy or nY			Places n lines in the bufferöcopies; omitting n copies only 
				the current line to the buffer.
ycursor_cmd			Copies from cursor to cursor_cmd (e.g., yG copies current 
				line to the last line in the file to the buffer).
"(a-z)nyy        		or
"(a-z)ndd			Copies or cuts (deletes) n lines into a named buffer a 
				through z; omitting n works on current line.
p				Pastes copied text after cursor; also prints last deleted 
				text.
P				Pastes copied text before the cursor; also prints last 
				deleted text.
"(a-z)p 			or
"(a-z)P			Pastes text from a named buffer a through z after or before 
				the current line.
nJ				Joins the next n lines together; omitting n joins the 
				beginning of the next line to the end of the current 
				line.
stext ESC			Substitutes text for the current character until ESC is 
				used.
S or cc text ESC		Substitutes text for the entire line until ESC is used.
cwtext ESC			Changes current word to text until ESC is used.
Ctext ESC			Changes rest of the current line to text until ESC is used.
ccursr_cmdtext ESC	Changes to text from current position to cursr_cmd until ESC
				is used.
u				Undoes last command.
U				Restores current line to its original state.
"np				Retrieves the last nth delete (last 9 deletes are kept in 
				a buffer).
"1pu.u.			Scrolls through the delete buffer until the desired delete 
				is retrieved (repeat u.). 
n				Repeats last / or ? search command.
N				Repeats, in reverse order, last / or ? search command.
; (semi-colon)		Repeats last f F t or T search command.
, (comma)			Repeats, in reverse direction, last / or ? search command.
. (period)			Repeats last text change command.
CTRLöi or TAB		While inserting, inserts one shift width.


EDITING  	(Deleting, copying, placing text, joining lines, changing text, repeat 
		command, undo command)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode.
n<< or n>>			Shifts n lines left or right (respectively) by one shift 
				width; omitting n shifts one line.
< or > 			Use with cursor command to shift multiple lines left or 
				right.


SHELL WORKS     (Commands that execute outside of the VI program.)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode. 
:! cmd			Executes shell command cmd; you can add these special 
				characters to indicate: 
%  				Name of current file 
#  				Name of last file edited
!! cmd			Executes shell command cmd, places output in file starting 
				at current line.
:!!				Executes last shell command.
:r! cmd			Reads and inserts output from cmd.
:f file			Renames current file to file.
:w !cmd			Sends currently edited file to cmd as standard input and 
				execute cmd.
:cd dir			Changes current working directory to dir.
:sh				Starts a sub-shell (CTRL-d returns to editor).
:so file 			Reads and executes commands in file (file is a shell script).
!cursor_cmd cmd		Sends text from current position to cursor_cmd to shell 
				command cmd.
!}sort  		Sorts from current position to end of paragraph and replaces 
				text with sorted text.


MACROS, SUBS, ABBREVIATIONS (Macro functions, substitution strings, & abbreviations)

COMMAND			RESULT

ESC 				Exits all modes except the initial Command Mode. 
:[address]s/search-string/replace-string/[/g]	
				This is the format of a substitute commandödescription below.
address			One line number or two line numbers separated by a comma. 
				A. represents the current line, $ represents the last line, 
				and % represents the entire file.
search-string 		A regular expression that can be a simple string of 
				characters.
replace-string 		The replacement string.
g				Indicates a global replacement (more than one replacement 
				per line).


SETTING OPTIONS 

COMMAND			RESULT

NOTE: Map allows you to define strings of VI commands. If you create a file called 
".exrc" in your home directory, any map or set command you place inside this file 
will be executed every time you run VI. To imbed control characters like ESC in the 
macro, you need to precede them with CTRLöv. If you need to include quotes ("), 
precede them with a \ (backslash). Unused keys in vi are: K V g q v * = and the 
function keys. 

:map v /I CTRLöv ESC dwiYou CTRLöv ESC ESC
				When v is pressed, search for "I" (/I ESC), delete word (dw), 
				and insert "You" (iYou ESC). CTRLöv allows ESC to be inserted. 
:map key cmd_seq		Defines key to run cmd_seq when pressed.	
:map				Displays all created macros on status line.


MACROS, SUBS, ABBREVIATIONS  (Macro functions, substitution strings, & abbreviations)

SETTING OPTIONS

COMMAND			RESULT

:unmap key 			Removes macro definition for key.	
:ab str string 		When str is input, replaces it with string.
:ab				Displays all abbreviations.	
:una str 			Unabbreviates str.

Options given are default. To change them, enter type :set option to turn them on 
or :set nooption to turn them off.  To make them execute every time you open VI, 
create a file in your HOME directory called .exrc and type the options without the 
colon (:) preceding the option.

COMMAND			RESULT

:set all			Prints all options to the screen.	
:set nooption 		Turns off option.
:set ai 			Turns on auto indentation.	
:set ap 			Prints line after d c J m :s t u commands.
:set bf			Discards control characters from input.	
:set eb			Precedes error messages with a bell.
:set ic			Ignores case when searching.	
:set dir=tmp 		Sets directory or buffer file.
:set lisp 			Modifies brackets for Lisp compatibility.	
:set magic 			Allows pattern matching with special characters.
:set mesg 			Allows others to send messages.	
:set list 			Shows tabs (^l) and end of line ($).
:set nu 			Shows line numbers.	
:set opt 			Speeds output; eliminates automatic RETURN.
:set prompt 		Prompts for command input with :.	
:set re 			Simulates smart terminal on dumb terminal.
:set report 		Indicates largest size of changes reported on status line.	
:set ro 			Changes file type to "read only."
:set scroll=n  		Set n lines for CTRLöd and z	
:set sh=shell_path 	Set shell escape (default is /bin/sh)
:set showmode 		Indicates input or replace mode at bottom.	
:set sw=n 			Sets shift width to n characters.
:set term 			Prints terminal type.	
:set terse 			Shorten messages with terse.
:set timeout 		Eliminates one-second time limit for macros.	
:set tl=n 			Sets significance of tags beyond n characters (0 means all).
:set ts=n 			Sets tab stops to n for text input.	
:set wa 			Inhibits normal checks before write commands.
:set warn 			Warns "no write since last change."	
:set window=n 		Sets number of lines in a text window to n.
:set wm=n 			Sets automatic wraparound n spaces from right margin.		


VI CORE COMMANDS (The minimum functions)

COMMAND			RESULT 

STARTING VI     (VI is Case Sensitive!!! So make sure Caps Lock is OFF.)

vi file 			Edit file
 
ENDING VI     		(Saving, exiting, etc.)

ZZ or :wq or :x		Saves and exits VI.
:q				Quits VI, saving changes before leaving. (You may be 
				prompted to save.)
:q!				Quits VI without saving changes.


MOVING    (These will tell you how to get the cursor where you want itöfast.)

MOVING THE CURSOR

COMMAND			RESULT

arrow keys			These do work, but they may be too slow on big files.
h j k l			Left, down, up, and right, respectively.
CTRL-d			Moves forward ¸ screenful.
CTRL-f			Moves forward 1 whole screenful.
CTRL-u			Moves backward ¸ screenful.
CTRL-b			Moves backward 1 entire screenful.
nG				Moves to line n in the file.
G				Moves to the end of file.
H				Moves to the top of the screen.
M				Moves to the middle of the screen.
L				Moves to the bottom of the screen.
w or W			Moves to the start of the next word in the line; W ignores 
				punctuation.
b or B			Moves to the start of the previous word in the line; B 
				ignores punctuation.
e or E			Moves to the end of the next word in the line; E ignores 
				punctuation.
^				Moves to the first non-blank character in the current line.
$				Moves to the last character in the current line.
+ or 			Moves to the first character in the next line.


MODES     (Adding and/or replacing text)

COMMAND			RESULT

itext ESC			Insert mode÷You can start typing, and it will insert text 
				before the letter your cursor currently highlights until ESC 
				is used.
atext ESC			Append mode÷This allows you to insert text after the letter 
				your cursor currently highlights until ESC is used.
Atext ESC			Append mode÷Same as (a) except it will insert text at the end 
				of the line until ESC is used.
rchar ESC			Replace mode÷Replaces the currently one highlighted character 
				with char until ESC is used.
Rtext ESC			Replace mode÷Same as (r) except it will overwrite until ESC 
				is used.
o				Opens new line below the current line and insert until ESC 
				is used.
O (letter "O")		Opens new line above the current line and insert until ESC 
				is used.


SEARCHING     (Find and/or replace what you need)

COMMAND			RESULT

fchar | Fchar		Searches forward in current line to char.  
				| Searches backward in current line to char.
/str  | ?str  	Finds forward to str.  | Finds in reverse for str.


EDITING    	(Deleting, copying, placing text, joining lines, changing text, repeat 
		command, undo command)

COMMAND			RESULT

CTRLöh  or Backspace	While inserting, deletes previous character.
CTRLöw			While inserting, deletes previous word 
nx				Deletes n characters starting with current; omitting n 
				deletes current character only.
ndw				Deletes the next n words starting with current; omitting n 
				deletes the current word only.
ndd				Deletes n lines beginning with the current line; omitting n 
				deletes the current line only.
D or d$			Deletes from the cursor to the end of the line.
nyy or nY			Places n lines in the bufferöcopies; omitting n copies only 
				the current line to the buffer.
p				Pastes copied text after cursor; also prints last deleted 
				text.
nJ				Joins the next n lines together; omitting n joins the 
				beginning of the next line to the end of the current line.
u				Undoes last command.
U				Restores current line to its original state.
n | N				Repeats last / or ? search command. | Repeats, in reverse 
				order, last / or ? search command.
. (period)			Repeats last text change command.
CTRLöi or TAB		While inserting, inserts one shift width.


OPTIONS

COMMAND			RESULT

Options given are default. To change them, enter type :set option to turn them on 
or :set nooption to turn them off.  To make them execute every time you open VI, 
create a file in your home directory called .exrc and type the options without the 
colon (:) preceding the option.

:set all			Prints all options to the screen.	
:set nooption 		Turns off option.
:set ic			Ignores case when searching.	
:set magic 			Allows pattern matching with special characters.
:set nu 			Shows line numbers.	
:set ro 			Changes file type to "read only."
:set scroll=n  		Sets n lines for CTRLöd and z.	
:set sw=n 			Sets shift width to n characters.
:set showmode 		Indicates input or replace mode at bottom.	
:set window=n 		Sets number of lines in a text window to n.
:set ts=n 			Sets tab stops to n for text input.	
:set wm=n 			Sets automatic wraparound n spaces from right margin.