Plan 9 from Bell Labs’s /usr/web/sources/contrib/steve/doc/sam-refcard.tbl

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


.\"sam refcard
.\" the formatting of this document is "incomplete"
.\" process as:  tbl sam-refcard.tbl | troff -ms | lp -L -dstdout | page
.\" expect a warning about the page being too wide, ignore it
.nr HM 0.5i
.nr FM 0.5i
.nr VS 10
.LL 8i
.pl 6.6i
.LG
.LG
.ce 1
.B
.UL "Sam quick reference card"
.sp 1
.R
.NL
.2C
.TS
;
lfB s
l|l  .
Addresses
_
n,m	line n to line m
'	address mark, see k below
 .	current selection/position
0	start of file
^	start of line
$	end of line/file
,	equivalent 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
\\#	substitute #'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 [file-name] 	Replace current with file
r file-name	Replace dot by contents of file
w file-name	Write current to named file
f [file-name]	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
<compose> Xnnnn	Insert char xxxx hex (Unix/Plan9)
Alt-nnnn	Insert char xxxx hex (Windows)
.TE
.bp
.TS
expand ;
lfB s
l|l  .
Sam idioms
_
X/.*/,x/<cr>/d	strip <cr> from all files
x/^\\/\\*/ \\.,/\\*\\/\\n/d	strip C comments from selection
-/^/+#10	goto the 10th colum in the current line
-0+,+0-	round dot down to whole lines only
,x/ +/ v/^/ c/ /	compress runs of spaces, leaving indentation
s/"([^"]*)"/``\\1''/	replace "hello" with ``hello'' in selection
f <nl>	set current file-name to null	
< echo "\\xxx"	insert ascii code xxx at current pos
, > wc -l	count lines in file
/text/+-p	highlight the lines containing <pat>
-/text/	search for text backwards
$-/text/	search for the last occurrence of text in file
,x/<text>/+-p	grep for text
\.x/<pat>/ c/<rep>/	search for <pat> and replace with <rep>
B < echo *.c	add all the C files in current dir to file list
B < grep -l <pat> *	add all the files containing <pat> to file list
X/'/w	write all modified files
Y/\\.c/D	remove all non C files from file list
| fmt	pipe selection through the text formatter
> mail <user>	send selection as Email to <user>
x/\\n+/ a/\\n/	double space selection
x/^/ a/ /	indent selection 1 tab
x/^<tab>/d	remove 1 tab of indent from selection
/(.+\\n)+/	matches blocks of text separated by blank lines
! date	get current date in sam window
,> wc	push file into wc, count appears in sam window
0 < date	insert 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 upper case
,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	capitalise every word (slow)
,x[a-zA-Z]+/{
  g/fred/ v/...../ c/jim/
  g/jim/ v/..../ c/fred/
}	swap fred for jim in file
.TE

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].