Useful EMACS Keystrokes for repetitive editing.


1) To cut out a large number of lines, place the cursor at the start of the text block and hit "^ " (Space bar while holding down Control key), this 'sets the mark'. Then move the cursor to the end of the text block and hit "^w" (CNTRL-W). This deletes the text and places it in a buffer. If you want, you can then move the cursor to a new point in the text and drop the deleted text there with "^y" (CNTRL-Y). You can drop the text as many times as you want.

 

2) To cut a rectangle out of a block of text, place the cursor at the upper-left corner of the desired rectangle and type "^ " (CNTRL-SPACE). Move the cursor to the lower-right corner of the desired rectangle and type "^x" (CNTRL-X). The cursor drops to the bottom line of the window, where you type "rk" (which stands for rectangle-kill). The rectangle of text is removed from the document and saved in the buffer. If you want, you can move the cursor to a new point in your document and drop the rectangle of text there by typing "^x" (CNTRL-X), and at the bottom of the screen, "ry" (for rectangle-yank). Try this on a practice document to see how it works. You can drop the text as many times as you want.

This trick is useful when writing IRAF scripts where you have a list of filenames produced by "files" and wish to place that list after itself, like this:

Initial files list:

bias01.fit
bias02.fit
bias03.fit

Copy the text behind itself like this: place cursor over b in bias01 and hit "^ " to set the mark. Then place the cursor over the f in bias03.fit and hit "^x" and type "rk" at the input line. Now place the cursor back where the b in bias01 was, and hit "^x" and type "ry" to replace that text. Now move the cursor to the t in bias01.fit, type a space or two to separate the columns, and type ^x" and type "ry" to drop the text there again. The result should look like this:

bias01.fit  bias01.
bias02.fit  bias02.
bias03.fit  bias03.

This is a lot of work for 3 lines of text, but for a whole night of images (50+ images?) it saves a lot of typing and potential typos! To complete the script, see the Hint #3.

 

3) To replace one chunk of text with another, do this: move to the top of the document with "ESC-<" (Escape key, then <). Type "ESC-%" and the cursor will appear at the bottom of the screen after "Query replace:". Type the bit of text you want to replace, e.g. 'fit' from above, and hit return. On the same line, it will prompt you for the text you want to replace it with. In our example, type "fit + 0. ". The first occurrence of 'fit' is highlighted, and the bottom line asks if you want to replace this occurrence -- your responses could be SPACEBAR for yes, n for no, and ! for "replace all occurrences and don't ask me anymore!". In our example, type ! and all result is:

bias01.fit + 0. bias01.
bias02.fit + 0. bias02.
bias03.fit + 0. bias03.

Now we'll try another twist. Do query/replace again, but instead of searching for 'fit', search for 'bias'. Replace it with 'imarith bias', but selectively chose SPACEBAR and n to only replace the first occurrence of 'bias' in each line, so you get:

imarith bias01.fit + 0. bias01.
imarith bias02.fit + 0. bias02.
imarith bias03.fit + 0. bias03.

 

4) To complete the script, move the cursor to the end of the top line, and type 'imh pix=s'. Then highlight this text with the cursor and hit the COPY key on the left side of your keyboard. Then type the down arrow key to move the cursor to the end of the next line, and hit the PASTE key. Repeat until all the lines are finished:

imarith bias01.fit + 0. bias01.imh pix=s
imarith bias02.fit + 0. bias02.imh pix=s
imarith bias03.fit + 0. bias03.imh pix=s

 


Andy Layden, BGSU Physics & Astronomy Dept, last updated 2003 March 26