Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tag: v0.0.1
Fetching contributors…

Cannot retrieve contributors at this time

42 lines (32 sloc) 1.936 kb
<h3 id="deleting-text">Deleting Text</h3>
<h4>Problem</h4>
<p>You wish to remove some text from a file. For example, you've typed a
paragraph which is no longer needed.</p>
<h4>Solution</h4>
<p>In Normal mode, move your cursor over the character to banish and hit
<kbd>x</kbd> (mnemonic: e<i>x</i>punge). This deletes characters under and
after the cursor; to delete characters before the cursor use <kbd>X</kbd>.
This is fine for single characters, but to delete words and other <a
href="#selecting-text-with-motions">text objects</a> you can use
<kbd>d<var>motion</var></kbd>.</p>
<p>If you'd rather nuke entire lines at a time use <kbd>dd</kbd>. So, to
delete the current line and the one following it: <kbd>2dd</kbd>. Use a
<i>range</i> prefix to delete the specified lines, e.g. <tt>:17,20d</tt>
deletes lines seventeen through to twenty.</p>
<p>A compromise is to delete the remainder of a line, which can be achieved
with <kbd>D</kbd>. If your cursor was positioned after <i>compromise</i> in
the above sentence, and you then hit <kbd>D</kbd>, the line would be changed
to just <i>A compromise</i>.</p>
<p>If you've selected a block of text <a
href="#visually-selecting-text">visually</a>, you can delete it all with
<kbd>x</kbd>.</p>
<h4>Discussion</h4>
<p>Vim doesn't just <i>delete</i> text; it saves it to a <i>register</i>
first. If you delete a small amount of text (less than a line), it's stored in
a register named <tt>"-</tt>. Otherwise, it's stored in <tt>"0</tt>, whose
existing contents are moved to <tt>"1</tt>, whose existing&hellip;right up to
<tt>"9</tt>. This allows you easy access to previously deleted text inasmuch
as you can recall, say, the 3<sup>rd</sup> most recently deleted line with
<kbd>"2p</kbd>. Even more usefully, you can use <tt>:registers</tt> to view
your recent deletions. The <a href="#undoing-mistakes">Undoing Mistakes</a>
recipe explains how to revert these deletions.</p>
Jump to Line
Something went wrong with that request. Please try again.