Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 1563771179
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (35 sloc) 2.121 kb
<h3 id="repeating-commands">Repeating Commands</h3>
<h4>Problem</h4>
<p>You've entered a command and want to repeat it without re-typing it.</p>
<h4>Solution</h4>
<p>The period <kbd>.</kbd> repeats the last command entered in <i>Normal</i>
mode. For example, <kbd>dd</kbd> deletes the current line; <kbd>dd..</kbd>
deletes the current line, then deletes the new current line, then deletes the
new current line. In other words, it repeats the command twice.</p>
<p>To repeat a command entered in <i>Command</i> mode hit
<kbd><kbd>:</kbd></kbd>, then <kbd>&#x2191;</kbd> to
scroll back through your command history. If you type the first few letters of
the command before using <kbd>&#x2191;</kbd>, the history will be limited
appropriately.</p>
<h4>Discussion</h4>
<p>The period command helps automating repetitive tasks with the fewest
keypresses. It lets you say <q>do that again</q>, but in only one character.
</p>
<p>If you know you want to execute a command <var>n</var> times, you can
prefix it with the integer <var>n</var>. The above example rewritten in this
way is <kbd><kbd>3dd</kbd></kbd>.</p>
<p>The second approach requires fewer keystrokes so is clearly preferable if
you know in advance how many times you want to repeat a command. However, the
period command lets you make that decision incrementally, after executing the
command.</p>
<p>You can combine these approaches by prefixing the period command with an
integer to say <q>do that <var>n</var> times again</q>:
<kbd><kbd><var>n</var>.</kbd></kbd>. Be aware that having done this, if you
use the period command again it will repeat your previous repetitions, i.e.
<kbd><kbd><var>command</var></kbd></kbd>, followed by
<kbd><kbd><var>n</var>.</kbd></kbd>, followed by <kbd><kbd>.</kbd></kbd> will
result in <var>command</var> being executed 2<var>n</var> + 1 times. </p>
<p>The discussion above assumes that the last command needs to be repeated
exactly. Instead, you may wish to execute a different command on the same
text. Jump to the line of the last change with the <i>Normal</i> mode
command <tt>'.</tt>, then make that change.</p>
Jump to Line
Something went wrong with that request. Please try again.