Emacs tutorial notes 17 November 2003 Mike Daniels Conventions: C-x means hold down the control key and press x S-x means hold down the shift key and press x M-X means hold down the meta key and press x OR press Escape, and then press x Note that C-S-x and C-X are the same thing. Files: C-x C-f opens files C-x i inserts a file C-x C-s saves a file C-x C-w saves a file with a different name Cursor navigation: C-a - beginning of line C-e - end of line C-f - forward character C-b - backward character M-f - forward word M-b - backward word C-n - next line C-p - previous line M-< - top of buffer M-> - end of buffer C-v - page down M-v - page up To bring emacs' cursor movement in line with windows conventions: M-x pc-selection-mode Undo: C-x u OR C-_ Cancel: C-g The basic help system: C-h i What does this key do? C-h k What command is appropriate for doing X? C-h a Selection: Use mouse to highlight, OR Type C-{SPACE} at the beginning of the region and move the cursor to the end OR M-h - select current paragraph C-x h - select entire buffer C-x C-p - select entire page Things to do with selected text: C-k - cut M-w - copy M-x print-region - print Use any command with "region" in its name. Paste: C-y Search and replace: C-s - incremental search C-M-s - incremental regexp-based search M-% - interactive search and replace C-M-% - interactive regexp-based search and replace Interactive search-and-replace: {SPACE} replace and continue OR y {DELETE} skip and continue OR n {RETURN} skip and stop OR q . replace and stop ! replace all ^ back up Typing a character literally: C-q [character] Window management: C-x b [buffername] - create a buffer, or switch to an existing one C-x 4 b [buffername] - do the above in another window C-x 5 b [buffername] - do the above in another frame C-x k [buffername] - get rid of buffer C-x 2 - split vertically C-x 3 - split horizontally C-x o - move to other window C-M-v - scroll other window (without moving to it) C-x {zero} - delete current window C-x {one} - delete other windows Frame management: C-x 5 2 - make new frame C-x 5 b [buffername] - put or create buffername in a new frame C-x 5 0 - get rid of frame C-x 5 o - move to other frame C-x 5 1 - delete other frames Customization: M-x customize Modes: C-h m - describe current modes Emacs at home: Emacs for windows can be obtained here: ftp://ftp.gnu.org/gnu/windows/emacs/latest/ See http://www.gnu.org/software/emacs/windows/ for installation instructions. Emacs for mac can be obtained here: http://mac-emacs.sourceforge.net/ Remote editing: C-x C-f /user@host:path/file Regular Expressions: {character} matches itself, unless {character} is one of the following \$ matches '$' \^ matches '^' \. matches '.' \* matches '*' \+ matches '+' \? matches '?' \[ matches '[' \] matches ']' \\ matches '\' . matches any single character except a newline ^ matches the beginning of a line \` ditto $ matches the end of a line \' ditto [{stuff}] matches any character inside the list {stuff} [A-Z] matches any capital letter (in the unaccented Latin alphabet) [0-9] matches any digit [A-Za-z_] matches any letter-or-underscore [^z] matches any letter that isn't 'z' note that tricks are involved if your character class needs to include ']', '-', or '^' \b matches the beginning or end of a word \bking\b will actually find the word "king" while ignoring "picnicking" \B matches that which is not the beginning or end of a word \Bking will only find the "king" in "picnicking" \< matches the beginning of a word \> matches the end of a word \w matches any word-constituent character \W matches any non-word-constituent character \cC matches any character belonging to category C (use M-x describe-categories to get possible values for C) \CC matches any character not belonging to category C modifiers: * matches zero-or-more of the previous expression + matches one-or-more of the previous expression ? matches zero-or-one of the previous expression [A-Z]* matches zero-or-more uppercase letters [0-9]? matches an optional digit [a-z][0-9A-Za-z_] prolog identifiers \{{num}\} matches num quantities of the previous expression i.\{18\}n matches "internationalization" (note that these are "greedy" operators -- they'll match as much as possible. Non-greedy versions are available in *?, +?, and ??) \| disjunction [a-z]*\|[A-Z]* matches a block of same-case letters \( and \) grouping - limits the scope of \| - allows *, +, ?, etc. to apply to a complex expression (e.g. ba\(na\)* matches bana, banana, bananana, etc. [insert obligatory joke here]) Exercise: This is the definition of "sentence end", a regexp used by emacs to match the end of a sentence along with any whitespace that follows. "[.?!][]\"')]*\\($\\| $\\|\t\\| \\)[ \t\n]*" This is in the syntax of a string literal, so all quotes and backslashes have been escaped. The actual characters in the string are therefore: [.?!][]"')]*\($\| $\|{tab}\| \)[ {tab}{newline}]* (where {tab} represents what you get when you hit the Tab key, ditto {newline}) So how does this work? Does it match your expectation of the end of a sentence? If not, how would you revise it so that it does?