.nr PS 11 .nr HM 0.5i .nr FM 0.5i .nr VS 0.141i .ce 1 .B .UL "Sam quick reference guide" .sp 1 .R .nr PS 8 .2C .TS ; lfB s l|l . Addresses _ n,m line n to line m ' address mark, see k below . currect selection/position 0 start of file ^ start of line $ end of line/file , equivilent to 0,$ .TE .TS ; lfB s l|l . Regular Expressions _ \. any character * 0 or more of previous + 1 or more of previous [^n] any char but n [nm] n or m [a-z] class a thru z (re) tag pattern \\# substute #'th tagged pattern .TE .TS ; lfB s l|l . Text commands _ -/re/ search backward +/re/ search forward /re/ search in same direction as last a/text/ Append text after dot c/text/ Change text in dot i/text/ Insert text before dot d Delete text in dot s/regexp/text/ Substitute text for regexp in dot m address Move dot to after address t address Copy dot to after address .TE .TS ; lfB s l|l . Display commands _ p Print contents of dot = Print value of dot n Print file menu list .TE .TS ; lfB s l|l . I/O commands _ b file-list Set current file to first in menu list B file-list As b, but load new file-list D file-list Delete named buffers e [filename] Replace current with file r filename Replace dot by contents of file w filename Write current to named file f [filename] Set current file name < command Replace dot by stdout of command > command Send dot to stdin of command | command Pipe dot through command ! command Run the command .TE .TS ; lfB s l|l . Loops and conditionals _ x/regexp/ command Set dot and run command on each match x cmd Set dot and run command on each matching line y/regexp/ command as x but select unmatched text X/regexp/ command Run command on files whose menu line matches Y/regexp/ command As X but select unmatched files g/regexp/ command If dot contains regexp, run command v/regexp/ command If dot does not contain, run command .TE .TS ; lfB s l|l . Miscellany _ k Set address mark to value of dot q Quit u n Undo last n (default 1) changes { } Braces group commands Xnnnn Insert char xxxx hex (Unix/Plan9) Alt-nnnn Insert char xxxx hex (Windows) .TE .TS ; lfB s l|l . Sam idioms _ X/.*/,x//d strip from all files x/^\\/\\*/ \\.,/\\*\\/\\n/d strip C comments from selection -/^/+#10 goto the 10th collum in the current line -0+,+0- round dot down to whole lines only ,x/ +/ v/^/ c/ / compress runs of spaces, leaveing indentation s/"([^"]*)"/``\\1''/ replace "hello" with ``hello'' in selection f set current filename to null < echo "\\xxx" insert ascii code xxx at current pos , > wc -l count lines in file /text/+-p highlight the lines containing -/text/ search for text backwards $-/text/ search for the last occurance of text in file ,x//+-p grep for text \.x// c// search for and replace with B < echo *.c add all the C files in current dir to file list B < grep -l * add all the files containing to file list X/'/w write all modified files Y/\\.c/D remove all non C files from filelist | fmt pipe selection thru the text formater > mail send selection as email to x/\\n+/ a/\\n/ double space selection x/^/ a/ / indent selection 1 tab x/^/d remove 1 tab of indent from selection /(.+\\n)+/ matches blocks of text seperated by blank lines ! date get current date in sam window ,> wc push file into wc, count appears in sam window 0 < date instert date at start of file 1 < date replace first line with todays date X D remove out all up-to-date files ,| sort sort current file ,x/^TODAY$/ < date replace TODAY on with the output of date ,x/Plan9/|tr a-z A-Z replace all instances of Plan9 with uppercase ,t "junk.c" 0 copy current file to start of junk.c -/.PP/,/.PP/- highlight current paragraph in an nroff doc ,x/[a-zA-Z0-9]+/ -#0;+#1 | tr a-z A-Z capatalise every word (slow) ,x[a-zA-Z]+/{ g/fred/ v/...../ c/jim/ g/jim/ v/..../ c/fred/ } swap fred for jim in file .TE