Navigation picture
20P10 — Navigation

Notes and cheatsheet on the sam editor

sam Editor

sam is the standard text editor on Plan 9.

A normal sam session begins with a new samterm window. You are expected to use the console at the top and mouse chording to manipulate files and edit text. sam behaves pretty much like ed if you invoke it with sam -d.

Cheatsheet

This is an HTML version of Steve Simon’s reference card.

Addresses
n,mline n to line m
address mark, see k below
.correct selection/position
0correct selection/position
ˆstart of file
$end of line/file
,equivalent to 0,$
Regular Expressions
.any character
*0 or more of previous
+1 or more of previous
[ˆn]correct selection/position
[nm]n or m
(re)tag pattern
#substitute #’th tagged pattern
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
dDelete text in dot
s/regexp/text/Substitute text for regexp in dot
m addressMove dot to after address
t addressCopy dot to after address
Display commands
pPrint contents of dot
=Print value of dot
nPrint file menu list
I/O commands
b file-listSet current file to first in menu list
B file-listAs b, but load new file-list
D file-listDelete named buffers
e [file-name]Replace current with file
r file-nameReplace dot by contents of file
w file-nameWrite current to named file
f [file-name]Set current file name
< commandReplace dot by stdout of command
> commandSend dot to stdin of command
| commandPipe dot through command
! commandRun the command
Loops and conditionnals
x/regexp/ commandSet dot and run command on each match
x cmdSet dot and run command on each matching line
y/regexp/ commandas x but select unmatched text
X/regexp/ commandRun command on files whose menu line matches
Y/regexp/ commandAs X but select unmatched files
g/regexp/ commandIf dot contains regexp, run command
v/regexp/ commandIf dot does not contain, run command
Miscellany
kSet address mark to value of dot
qQuit
u nUndo last n (default 1) changes
{ }Braces group commands
XnnnnInsert char xxxx hex (Unix/Plan9)
Alt-nnnnInsert char xxxx hex (Windows)
Sam idioms
X/.*/,x//dstrip <cr> from all files
x/ˆ/ .,/0dStrip C comments from selection
-/ˆ/+#10goto 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 ""insert ascii code xxx at current pos
, > wc -lcount lines in file
/text/+-phighlight the lines containing <pat>
-/text/search for text backwards
$-/text/search for the last occurrence of text in file
,x/<text>/+-pgrep for text
.x/<pat>/ c/<rep>/search for <pat> and replace with <rep>
B < echo *.cadd all the C files in current dir to file list
B < grep -l <pat> *add all the files containing <pat> to file list
X/’/wwrite all modified files
Y/.c/Dremove all non C files from file list
| fmtpipe selection through the text formatter
> mail <user>send selection as Email to <user>
x/0 a/0double space selection
x/ˆ/ a/ /indent selection 1 tab
x/ˆ<tab>/dremove 1 tab of indent from selection
/(.+0+/matches blocks of text separated by blank lines
! dateget current date in sam window
,> wcpush file into wc, count appears in sam window
0 < dateinsert date at start of file
1 < datereplace first line with todays date
X Dremove out all up-to-date files
,| sortsort current file
,x/ˆTODAY$/ < datereplace TODAY on with the output of date
,x/Plan9/|tr a-z A-Zreplace all instances of Plan9 with upper case
,t "junk.c" 0copy 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-Zcapitalise every word (slow)
,x[a-zA-Z]+/{
g/fred/ v/...../ c/jim/
g/jim/ v/..../ c/fred/
}
swap fred for jim in file

1 incoming links

cpu auth