maw.gay: "not so far from the bottom now"
sam(1) ssam(1) acme sam cheatsheet of sorts
'structural' regular expressions, meaning, looking at the entire body of the text, not line-by-line "A regular expression in sam matches the longest leftmost substring formally matched by the expression."
addresses: simple addresses: #n empty string after character n (#0 beginning of file) n line n /regexp/ forward regex search ?regexp? backward regex search - points to a substring - may wrap around file, may straddle starting point $ null string at end of file . dot, "current substring" ' the mark in the file (see k) "regexp" (preceeding a simple address)... - refers to address evaluated in the unique file (?) whose... - menu line matches the regular expression (?) compound addresses: a1+a2 address a2 evaluated starting at the end of a1 a1-a2 address a2 evaluated looking backwards from a1 a1,a2 the substring from beginning of a1 to end of a2 - a1 default 0, a2 default $ a1;a2 like a1,a2 but a2 evaluated at end of a2 - sets dot to a1 additional tricks: - a2 defaults to 1 (if it's a line or character address with a missing number) - if a1 is missing, . is substituted - if a1 and a2 are present and distinguishable, + may be elided - a2 may be a regular expression - if it is delimited by ?s, the effect of the + or - is reversed
commands: a/text/ insert the text into the file after the range - can also take the form of a lone a, several lines of text, then a lone . c same as a, but c replaces text in range i same as a, but inserts before rather than after d delete text in range, set dot s/regexp/text/ substitute first match to regexp in the range - set dot to the modified range - & stands for the string that matched expression - \d (where d is a digit) stands for the string that match the subexpression... - begin by the dth left paren - if s is followed immediately by a number... - (such as s2/x/y/) - ...the nth match in the range is substituted - if the command is followed by a g, as in s/x/y/g, - all matches in the range are substituted m a1 move range to after a1 t a1 copy range to after a1 p print the text in the range, set dot = print the line address and character address of the range =# print just the character address of the range b file-list set the current file to the first file named in the list that same also has in its menu B file-list same as b, except that file names not in the menu are entered there n print a menu of files D file-list delete named files from the menu e filename replace the file by the contents of the named external file - set dot to the beginning of the file r filename replace the text in the range by the contents of the named external file - set range w filename write range (default 0,$) to named external file f filename set filename and print resulting menu entry < 9cmd replace the range by the standard output of the plan 9 command > 9cmd send the range to the standard input of the plan 9 command ^ 9cmd send standard output of the plan 9 command to the command window | 9cmd send the range to the standard input, and replace it by the standard output, of the command _ 9cmd send the range to stdin, and send stdout of command to command window ! 9cmd run the plan 9 command cd dir change working directory x/regexp/ cmd for each match of regexp in range, run command with dot set to the match - then set dot to last match - if regexp and its slashes are omitted, /.*\n/ is assumed y/regexp/ cmd like x, but run command for each substring that lies before, between, or after matches X/regexp/ cmd for each file whose menu entry matches regular expression, run command in it Y/regexp/ cmd like X but for files that dont match g/regexp/ cmd if range contains match for regexp, set dot to the range and run the command v/regexp/ cmd if range does not contain match for regexp, set dot to the range and run the command the last block of commands may be nested arbitrarily deeply commands that do not accept a range to operate over: b B n D e f ! cd X Y
idioms: a1+- (a1-+) selects the line containing the end (beginning) of a2 0/regexp/ first match of expression in the file ./regexp/// finds the second following occurrence of the expression .,/regexp/ extends dot
Edit in acme(1) implements all the commands of sam(1) except: - k - n - q - ! And modifies: - = - includes the file name and gives only the line address unless the command is explicitly =#
license ∆ Tue Mar 23 18:17:18 EDT 2021