Emacs is incredibly useful for repetitive editing chores. For example, this Xah Lee post shows how Lee performed major surgery on hundreds of pages of HTML by using a little Emacs Lisp.
Not everyone can or wants to write Emacs Lisp but even without it you can still do a lot of automation with keyboard macros. Most Emacs users are familiar with the fundamentals: use 【Ctrl+x (】 or 【F3】 to start recording your keystrokes, perform the repetitive action one time and stop the recording with 【Ctrl+x )】 or 【F4】. Then you can repeat the keystrokes with 【Ctrl+x e】. After the first repeat you can simply type 【e】 for subsequent repeats.
Here’s a little trick I learned from the EmacsWiki. Suppose you want to create a list of host names where each differs from the others by a number at the end
host1.irreal.org host2.irreal.org ...
To do that, follow these steps
- 【Ctrl+x Ctrl+k Ctrl+a】
1
to set the amount to increment the counter on each repetition. - 【Ctrl+x Ctrl+k Ctrl+c】
1
to set the initial value of the counter. - 【Ctrl+x (】 to start recording the macro
host
【Ctrl+x Ctrl+k Ctrl+i】 to insert the current counter value after host..irreal.org
【Return Ctrl+x )】 to stop recording the macro.- 【Ctrl+x e】 to generate the next host name.
- 【e】 to generate another and so on.
You can also use 【Ctrl+x Ctrl+k Ctrl+f】 to set the format of the counter.