Skip to content
This repository
tag: v0.0.1
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (36 sloc) 2.114 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<h3 id="visually-selecting-text">Visually Selecting Text</h3>

<h4>Problem</h4>

<p>You want to interactively select some text by drawing a box around it, thus
enabling you to perform a command that affects it. In other words, you want to
select a text like you would in a <abbr title="Graphical User
Interface">GUI</abbr> word processor using either the keyboard or, in
<i>Gvim</i>, the mouse.</p>

<h4>Solution</h4>

<p>To select text character by character change to <i>Visual</i> mode with
<tt>&lt;Esc&gt;-v</tt>, then <a href="#basic-navigation">move the cursor as
  normal</a> using the <tt>h</tt>,<tt>j</tt>,<tt>k</tt>,<tt>l</tt> keys. For
example, to select the current character and the three that follow hit
<tt>&lt;Esc&gt;-v</tt>, then <tt>3l</tt>. To select the current paragraph:
<tt>&lt;Esc&gt;-v</tt>, then <tt>ap</tt>.</p>

<p>To select text by lines switch to <i>Visual Line</i> mode with
<tt>&lt;Esc&gt;-V</tt>, then move upwards and downwards with <tt>k</tt> and
<tt>j</tt> as normal. For example, to select the current line and the 2
following it hit <tt>&lt;Esc&gt;-V</tt>, then <tt>2j</tt>.</p>

<p>To select text in vertical blocks, or 'columns' to the rest of us, you use
<i>Visual Block</i> mode with <tt>&lt;Esc&gt;-&lt;Ctrl&gt;-v</tt>. For
example, if you wanted to select the first two characters of the current line
and the 20 following, you'd position your cursor on the first character of the
first line you're interested in, hit <tt>&lt;Esc&gt;-&lt;Ctrl&gt;-v</tt>, move
one character to the right (<tt>l</tt>), then move down 20 lines with
<tt>20j</tt>.</p>

<h4>Discussion</h4>

<p>As you get used to Vim's movement command, you'll have less of a need for
the various visual modes. Regardless, they can still be convenient when you're
making complex selections or aren't really sure what you're doing. ;-)</p>

<p>The point of selecting text is to operate on it. Here are some common
actions:</p>

<ul>
  <li><a href="#copying-cutting-pasting">Copy/cut it</a>.</li>
  <li>Format it, e.g. <kbd>gq</kbd>.</li>
  <li><a href="#indenting-lines">Indent/unindent it</a>.</li>
</ul>
Something went wrong with that request. Please try again.