Help With Commands: Keyboard Macros
Help With Commands: Keyboard Macros
Keyboard macros are a way to remember a fixed sequence of keys for later repetition. They're handy
for automating some boring editing tasks.
F3 Start recording macro
F4 Stop recording macro
F4 Play back macro once
M-5 F4 Play back macro 5 times
M-0 F4 Play back macro over and over until it fails
For example, this sequence of keys does the exact same transformation that we did with regular
expression replacement earlier, that is, it transforms a line containing George Washington to
WASHINGTON, George:
M-d C-d M-u , [SPC] C-y C-n C-a
After we record that key sequence as a macro, we can type M-0 F4 to transform the buffer pictured
earlier; in this case, Emacs runs the macro repeatedly until it has reached the end of the buffer.
See (info "(emacs)Keyboard Macros") for more information.
For example, C-h k C-s and C-h f isearch-forward RET both display a page describing
incremental search:
This is handy, for example, if you don't remember what C-s does, or if you remember that it invokes
incremental search but want to know more about that feature. The documentation gives the full name of
the command, shows which (if any) keys are bound to it, and gives a complete description of what the
command does.
On the other hand, if you don't remember how to invoke a particular feature, you can use apropos to
search for it:
C-h a
Search for commands by keywords or regexp
For example, if I remember that I want to activate narrowing, but don't remember how, I can type C-h
a narrow RET which shows a brief list of commands having to do with narrow, one of which is M-
x narrow-to-region.
Starts a shell in the buffer named *shell*, switching to it if it already exists. Use C-u M-x
shell to use a buffer with a different name.
M-x compile
Invokes make (with targets and options of your choice) and displays output in a new buffer.
Emacs identifies error lines containing filenames and line numbers, and you can click on them to
jump directly to the corresponding buffer and line.
M-x gdb
Invokes gdb in a new buffer. You can use the gdb command line as usual in that buffer. However,
Emacs lets you set breakpoints directly from your source buffers and shows execution by
marking the active line in your source buffers. Emacs can also display breakpoints, the stack, and
locals, simultaneously and each in their own window.
M-x grep
Invokes grep and prints results in a new buffer. Like M-x compile, when you click on a
match Emacs opens the correct file and takes you to the matching line.
M-x man