From charlesreid1

command line syntax
--------------------

-o[num]
start vim with num open windows (default is to open 1 window for each file)

-n
no swap file, edit files in memory

-s scriptfile
execute commands given in scriptfile as though they were typed from keyboard

-t tag
edit file contaning tag and position cursor at its definition (see ctags note)

-y
modeless vi, run in insert mode only w/o command mode

NOTE ON CTAGS:

ctags [options] files

create list of function and macro names defined in the specified C, pascal, fortran, yacc, lex (c++, java, perl, python, flex, bison if exuberant ctags) source "files"
output list (named tags by default) contains lines of form:
name   file   context
where name is functi onor macro name
file is source file in which name is defined
context is search pattern that shows line of code containing nae

after list of tags created, you can invoke vi on any file and type
:set tags=tagfile
:tag name

this switches vi editor to source file associated wit hthe "name" listed in "tagsfile" (which you specify with -f)


vi commands
-------------

commands have syntax:
[n] operators [m] motion

basic editing operators are:
c = begin change
d = begin delete
y = begin yank/copy

for current line, motion is same as operator (e.g. cc or yy)

cw  	 change word
cc  	 change line
c$  	 change text from current position to end of line
C   	 same as c$

dd   	delete current line
numdd	delete num lines
d$   	delete from now to end of line
D    	same as d$
dw   	delete word
d}   	delete up to next paragraph
d^   	delete back to beginning of line
d/pat  	delete everything up to first occurence of pattern
dn   	delete everything up to next occurrence of pattern
dfx  	delete everything up to and including x on current line
dtx  	delete everything up to but not including x on current line
dL   	delete up to last line on screen
dG   	delete up to end of file

<	shift text described by following motion command left 1 shiftwidth
<}	shift left all text up to next paragraph
<<	shift left current line
<%	shift left until matching parenthesis/brace/bracket (cursor must be on matching symbol)

g~w  	switch case of word
guw  	change to lowercase
gUw  	change to uppercase

p    	"push"/insert last deleted/yanked word AFTER cursor
P(cap) 	insert last deleted/yanked word BEFORE cursor
gp   	same as p but leave cursor at end of text
gP   	same as P but leave cursor at end of text
]p   	same as p but match indention
[p   	same as ]p

Rtext  	replace with new text (overwrite) beginning at curosr; use ESC to end replace mode

u   	undo last change
C-R 	redo last change
U   	restore current line
.   	repeat last change
~   	reverse case, move cursor right
C-A 	increment # under cursor
C-X 	decrement # under cursor

Y   	copy current line
yy  	copy current line
ye  	copy text to end of word
"xyy  	copy current line to register x
"xdd 	delete current line into register x
"xp     put contents of register x
J       join current line to next line


opening/writing/closing/etc
----------------------------

ZZ  		quit, write only if changes made
:x  		same as ZZ

:n,mw file     	write lines n thru m to file
:n,mw >> file  	appends lines n to m to existing file

:e file        	edit another file, current file becomes alternate
C-G            	show current file and line number


window commands
----------------

:new		open new window
:new file	open file in new window
:sp [file]	split current window; with file, edit that file in the new window
:vsp [file]	like sp but vertical split
:clo		close current window
:hid		hide current window
:on		make current window only visible window
:res num	resize window to num lines
:wa 		write all buffers
:qa		quit all buffers

C-W s		split current window
C-W n		open new window

C-W j		move cursor to previous window
C-W k		move cursor to next window
C-W p		move cursor to previous window
C-W t		move cursor to top window
C-W b		move cursor to bottom window
C-W h 		move cursor to left window
C-W l           move cursor to right window

C-W H		move current window to far left
C-W L		move current window to far right
C-K		move current window to very top
C-W B 		move current window to very bottom

C-W r		rotate windows down
C-W R		rotate windows up

C-W +		increase current window size
C-W -		decrease current window size
C-W =		make all windows same height


interacting with system
------------------------

:r file		read contents of file in after cursor
:r !command	read in output from command after current line
:numr !command	like above, but reads in after line num (0 = top of file)
:!command	run command, then return
!motion command		send textcovered by motion to unix command, replace with output
:n,m! command		send lines n to m to unix command, replace with output
:!!		repeat last system command
:sh		create subshell; return to editor with EOF (C-D)
C-Z		suspend editor; resume with fg
:so file	read and execute ex commands from file

K		look up word under cursor in man pages

macros
--------

:ab in out	use in as an abbreviation for out in insert mode
:unab in	remove abbreviations for in
:ab		list abbreviations

:map string sequence	map characters string as sequence of commands
			use #1, #2, etc as function keys
:unmap string		remove map for string
:map			list character strings that are mapped
:map! string sequence	map characters string to INPUT mode sequence
:unmap! string		remove input mode map
:map!			list maps in input mode

(control keys: ^A ^K ^O etc.)

qx			record typed characters into register specified by letter x
			if letter is uppercase, APPEND to register
q			stop recording
@x			execute register specified by letter x
@@			repeat last @ command