Advertisement
Guest User

sam-editor-commands-and-idioms.md

a guest
Jul 15th, 2015
300
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.20 KB | None | 0 0
  1.  
  2. Sam quick reference card
  3. ===
  4.  
  5. Addresses
  6. ---
  7.  
  8. n,m
  9.  
  10. line n to line m
  11.  
  12.  
  13. address mark, see k below
  14.  
  15. .
  16.  
  17. correct selection/position
  18.  
  19. 0
  20.  
  21. start of file
  22.  
  23. ˆ
  24.  
  25. start of line
  26.  
  27. $
  28.  
  29. end of line/file, equivalent to 0,$
  30.  
  31. Regular Expressions
  32. ---
  33.  
  34. .
  35.  
  36. any character
  37.  
  38. *
  39.  
  40. 0 or more of previous
  41.  
  42. +
  43.  
  44. 1 or more of previous
  45.  
  46. [ˆn]
  47.  
  48. any char but n
  49.  
  50. [nm]
  51.  
  52. n or m
  53.  
  54. [a-z]
  55.  
  56. class a thru z
  57.  
  58. (re)
  59.  
  60. tag pattern
  61.  
  62. #
  63.  
  64. substitute #’th tagged pattern
  65.  
  66. Text commands
  67. ---
  68.  
  69. -/re/
  70.  
  71. search backward
  72.  
  73. +/re/
  74.  
  75. search forward
  76.  
  77. /re/
  78.  
  79. search in same direction as last
  80.  
  81. a/text/
  82.  
  83. Append text after dot
  84.  
  85. c/text/
  86.  
  87. Change text in dot
  88.  
  89. i/text/
  90.  
  91. Insert text before dot
  92.  
  93. d
  94.  
  95. Delete text in dot
  96.  
  97. s/regexp/text/
  98.  
  99. Substitute text for regexp in dot
  100.  
  101. m address
  102.  
  103. Move dot to after address
  104.  
  105. t address
  106.  
  107. Copy dot to after address
  108.  
  109. Display commands
  110. ---
  111.  
  112. p
  113.  
  114. Print contents of dot
  115.  
  116. =
  117.  
  118. Print value of dot
  119.  
  120. n
  121.  
  122. Print file menu list
  123.  
  124. I/O commands
  125. ---
  126.  
  127. b file-list
  128.  
  129. Set current file to first in menu list
  130.  
  131. B file-list
  132.  
  133. As b, but load new file-list
  134.  
  135. D file-list
  136.  
  137. Delete named buffers
  138.  
  139. e [file-name]
  140.  
  141. Replace current with file
  142.  
  143. r file-name
  144.  
  145. Replace dot by contents of file
  146.  
  147. w file-name
  148.  
  149. Write current to named file
  150.  
  151. f [file-name]
  152.  
  153. Set current file name
  154.  
  155. < command
  156.  
  157. Replace dot by stdout of command
  158.  
  159. > command
  160.  
  161. Send dot to stdin of command
  162.  
  163. | command
  164.  
  165. Pipe dot through command
  166.  
  167. ! command
  168.  
  169. Run the command
  170.  
  171. Loops and conditionals
  172. ---
  173.  
  174. x/regexp/ command
  175.  
  176. Set dot and run command on each match
  177.  
  178. x cmd
  179.  
  180. Set dot and run command on each matching line
  181.  
  182. y/regexp/ command
  183.  
  184. as x but select unmatched text
  185.  
  186. X/regexp/ command
  187.  
  188. Run command on files whose menu line matches
  189.  
  190. Y/regexp/ command
  191.  
  192. As X but select unmatched files
  193.  
  194. g/regexp/ command
  195.  
  196. If dot contains regexp, run command
  197.  
  198. v/regexp/ command
  199.  
  200. If dot does not contain, run command
  201.  
  202. Miscellany
  203. ---
  204.  
  205. k
  206.  
  207. Set address mark to value of dot
  208.  
  209. q
  210.  
  211. Quit
  212.  
  213. u n
  214.  
  215. Undo last n (default 1) changes
  216.  
  217. { }
  218.  
  219. Braces group commands
  220.  
  221. <compose> Xnnnn
  222.  
  223. Insert char xxxx hex (Unix/Plan9)
  224.  
  225. Alt-nnnn
  226.  
  227. Insert char xxxx hex (Windows)
  228.  
  229.  
  230. Sam idioms
  231.  
  232. X/.*/,x//d
  233.  
  234. strip <cr> from all files
  235.  
  236. x/ˆ/ .,/0d
  237.  
  238. strip C comments from selection
  239.  
  240. -/ˆ/+#10
  241.  
  242. goto the 10th colum in the current line
  243.  
  244. -0+,+0-
  245.  
  246. round dot down to whole lines only
  247.  
  248. ,x/ +/ v/ˆ/ c/ /
  249.  
  250. compress runs of spaces, leaving indentation
  251.  
  252. ,s/"([ˆ"]*)"/‘‘1’’/
  253.  
  254. replace "hello" with ‘‘hello’’ in selection
  255.  
  256. f <nl>
  257.  
  258. set current file-name to null
  259.  
  260. <
  261.  
  262. echo ""
  263.  
  264. insert ascii code xxx at current pos
  265.  
  266. , > wc -l
  267.  
  268. count lines in file
  269.  
  270. /text/+-p
  271.  
  272. highlight the lines containing <pat>
  273.  
  274. -/text/
  275.  
  276. search for text backwards
  277.  
  278. $-/text/
  279.  
  280. search for the last occurrence of text in file
  281.  
  282. ,x/<text>/+-p
  283.  
  284. grep for text
  285.  
  286. .x/<pat>/ c/<rep>/
  287.  
  288. search for <pat> and replace with <rep>
  289.  
  290. B < echo *.c
  291.  
  292. add all the C files in current dir to file list
  293.  
  294. B < grep -l <pat> *
  295.  
  296. add all the files containing <pat> to file list
  297.  
  298. X/’/w
  299.  
  300. write all modified files
  301.  
  302. Y/.c/D
  303.  
  304. remove all non C files from file list
  305.  
  306. | fmt
  307.  
  308. pipe selection through the text formatter
  309.  
  310. > mail <user>
  311.  
  312. send selection as Email to <user>
  313.  
  314. x/0 a/0
  315.  
  316. double space selection
  317.  
  318. x/ˆ/ a/ /
  319.  
  320. indent selection 1 tab
  321.  
  322. x/ˆ<tab>/d
  323.  
  324. remove 1 tab of indent from selection
  325.  
  326. /(.+0+/
  327.  
  328. matches blocks of text separated by blank lines
  329.  
  330. ! date
  331.  
  332. get current date in sam window
  333.  
  334. ,> wc
  335.  
  336. push file into wc, count appears in sam window
  337.  
  338. 0 < date
  339.  
  340. insert date at start of file
  341.  
  342. 1 < date
  343.  
  344. replace first line with todays date
  345.  
  346. X D
  347.  
  348. remove out all up-to-date files
  349.  
  350. ,| sort
  351.  
  352. sort current file
  353.  
  354. ,x/ˆTODAY$/ < date
  355.  
  356. replace TODAY on with the output of date
  357.  
  358. ,x/Plan9/ | tr a-z A-Z
  359.  
  360. replace all instances of Plan9 with upper case
  361.  
  362. ,t "junk.c" 0
  363.  
  364. copy current file to start of junk.c
  365.  
  366. -/.PP/,/.PP/-
  367.  
  368. highlight current paragraph in an nroff doc
  369.  
  370. ,x/[a-zA-Z0-9]+/ -#0;+#1 | tr a-z A-Z
  371.  
  372. capitalise every word (slow)
  373.  
  374. ,x[a-zA-Z]+/{
  375. g/fred/ v/...../ c/jim/
  376. g/jim/ v/..../ c/fred/
  377. }
  378.  
  379. swap fred for jim in file
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement