Practical Emacs Tip #1: Meet the C-x z command

#linux

The Emacs manual simply states that “Repear the most recently executed command”.

This command just repeats the last command with the last given set of arguments to that command (if any). No rocket science. Just simple Emacs!

By the way, before we start there is one more thing - Once you press C-x z, you can repeatedly press only z for the command to repeat itself! No need to press C-x again and again.

Let’s take few examples:

Key SequenceBuffer ContentsComments
{start}Line OneStarting buffer content
Line Two
Line Three
C-d (delete a character)ine One1 character was deleted
Line Two
Line Three
C-x z (repeat)ne OneRepeating the precious command
Line Two
Line Three
ze OneRepeating one more time. Note that C-x is not used
Line Two
Line Three
zzzneRepeat few more times without the prefix command
Line Two
Line Three

Repeat can be used after anything. I mean ANYTHING! Even if you have something like this C-u 20 C-k, you can use repeat and one more set of 20 lines will be killed! Don’t worry you can also undo with this if you screw up a lot!