Chapter 3 Moving Around in a Hurry

^F: scroll forward one screen.
^B: scroll backward one screen.

^D: scroll forward half screen.
^U: scroll backward half screen.

^E: scroll forward one line.
^Y: scroll backward one line.

zENTER: move current line to top of screen and scroll.
z.: move current line to center of screen and scroll.
z-: move current line to bottom of screen and scroll.

H: move to home-the top line of screen.
M: move to middle line of screen.
L: move to bottom line of screen.

ENTER: move to first character of next line.
+: move to first character of next line.
-: move to first character of previous line.

^: move to first nonblank character of current line.
n|: move to column n of current line.

e: move to end of word.
E: move to end of ward(ignore punctuation)

(: move to begining of current sentence.
): move to begining of next sentence.

{: move to begining of current paragraph.
}: move to begining of next paragraph.

[[: move to begining of current section.
]]: move to begining of next section.

/pattern: search forward for pattern.
?pattern: search backward for pattern.

n: repeat last search.
N: repeat last search in opposite direction.

/: repeat last search forward.
?: repeat last search backward.

fx: find next occurrence of x in the line, where x stands for any character.
Fx: find previous occurrence of x in the line.

tx: find character before next occurrence of x in the line.
Tx: find character after previous occurrence of x in the line.

;: repeat previous find command in same direction.
,: repeat previous find command in opposite direction.

: returns you to your original position(the position where you issued the last G command). '': act same as, except that it returns the cursor to the begining of the line.

^G: show current line(not a movement command)

Chapter 4 Beyond the Basics

vim +n file: opens file at line number n
vim + file: opens file at last line
vim +/pattern file: opens file at the first occurence of pattern
vim -c command file: run command after opening file, usually a line number or a search.

vim -R file: operate in read-only mode.
vim -r file: recover files after a crash.
view file: to look at a file in read-only mode.

“[a-z]command: do command with buffer [a-z].
“[a-z]p: put the contents of buffer [a-z] after cursor.
“[A-Z]command: accumulate the text dealed by command to buffer named [a-z].

mx: mark current position with x.
‘x: move cursor to first character of the line marked by x.
`x: move cursor to character marked by x.
``: return to exact position of previous mark or context after a move.
‘’: return to begining of the line of previous mark or context.

Chapter 5 Introducint the ex Editor

=: print total number of lines.
.=: print line number of current line.
/pattern/=: print line number of first line that matches pattern.

start,end[delete|d]: delete lines.
start,end[move|m]number: move lines from start through end to number line.
start,end[copy|co|t]number: copy lines from start through end to number line.

/pattern/d: delete next line containing pattern.
/pattern/+d: delete line below next line containing pattern.
/patter1/,/pattern2/d: delete from first line containing patter1 through first line containing pattern2.

g/pattern: find last occurence of pattern in file.
g/pattern/p: find and display all lines in file containing pattern.
g!/pattern/nu: find and diaplay all lines in file that don’t contain pattern;also display the line number for each line found.

[read|r] filename: read in contents of another file with ex command.

Chapter 6 Global Replacement

put troff italicization codes around the wrod ENTER: :%s/ENTER/\fI&\fP/g

modify a list of pathnames in a file: :%s:/home/time:/home/linda:g

put html italicization codes around the wrod ENTER: :%s:ENTER:&:g

change all periods to semicolons in lines 1 to 10: :1,10s/./;/g

change all occurrences of the word help (or Help) to HELP: :%s/[Hh]elp/HELP/g

replace one or more spaces with a single space: :%s/ */ /g

replace one or more spaces following a colon with two spaces: :%s/: */: /g

replace one or more spaces following a period or a colon with two spaces: :%s/([:.]) */\1 /g

standardize various uses of a word or heading: :%s/^Note[ :s]*/Notes: /g

delete all blank lines: :g/^$/d

delete all blank lines, plus any lines that contain only whitespace: :g/^[ tab]*$/d

delete all leading spaces on every line: :%s/^ (.)/\1/

delete all spaces at the end of every line: :%s/(.) $/\1/

insert a > at the start of every line in a file: :%s/^/> /

add a period to the end of the next six lines: :.,+5s/$/./

reverse the order of all hyphen-separated items in a list: :%s/(.) - (.)/\2 - \1/

change every letter in a file to uppercase: :%s/.*/\U&/

reverse the order of lines in a file: :g/.*/mo0

in a text-file database, on all lines not marked Paid in full, append the phrase Overdue: :g!/Paid in full/s/$/ Overdue/

for any line that doesn’t begin with a number, move the line to the end of the file: :g!/^[[:digit:]]/m$

remove numbering from section headings in a document: :%s/^[1-9][0-9].[1-9][0-9.] //

Chapter 7 Advanced Editing

execute unix command: !command
enter shell without exit vim: !sh

examples: r!date, r!sort file, !ls

filter text in ex: start,end!sort

word abbreviation: ab abbr phrase

disable abbreviation: unab abbr

map x sequence : define character x as a sequence of editing commands.
unmap x: disable the squence defined for x.
map: list the characters that are currently mapped.

Chapter 11: Multiple Windows in Vim

vim -o[number] file1 file2: opens the edit session with display hrizontally split into number(default is two) equal-sized windows, one for each file.

[n]split [++opt] [+cmd] [file]:
n: tells how many lines to display in the new window, which goes at the top.
opt: passes vim option information to the new window session (note that it must be preceded by two plus signs).
cmd: passes a command for execution in the new window (note that it must be preceded by a single plus sign).
file: specifies a file to edit in the new window.

sviw filename: splits screen horizontally to open a new window and sets readonly for that buffer.
sfind [++opt] [+cmd] filename: works like :split, but looks for filename in path. if vim does not find the file, it doesn’t split the window.

resize -n: decrease current window size, default amount is one line.
resize +n: increase current window size, default amount is one line.

resize n: set current window height, default is to maximize window height.
vertical resize n: set current window width to n. default is to make window as wide as possible.