Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
65 lines (52 sloc) 2.71 KB
<h3 id="choosing-right-mode">Choosing the Right Mode</h3>
<p>You know that Vim has multiple modes of operation but aren't sure when to use
which one.</p>
<p>For practical purposes there are four modes:</p>
<dt>Insert mode</dt>
<dd>Use only for typing; not moving around or editing. Stay in
this mode for as short a time as possible.</dd>
<dt>Normal mode</dt>
<dd>Use this for editing: moving around the file, changing
text, and rearranging structure. Dip in and out of Insert mode when
<dt>Visual mode</dt>
<dd>Use this for <a href="#visually-selecting-text">visually selecting
text</a> so that you can cut, copy, or format it.</dd>
<dt>Command-Line mode</dt>
<dd>Use this for entering commands, e.g. <tt>:set number</tt></dd>
<p>Vim's modal approach to editing can seem confusing, but it really is the key
to understanding Vim.</p>
<p>It's tempting to spend much of your time in Insert mode, and <a
href="#basic-navigation">navigate with the arrow keys</a>. However, this is
slow and requires an awful lot of key presses. </p>
<p>Normal mode is the default mode because it makes it so easy to move around the
file to either edit existing text or position the cursor where you want to
insert text. </p>
<blockquote class="tip">
<p>Use <kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>o</kbd></kbd> in Insert mode to
switch to Normal mode for one command, then return to Insert mode. For
example, <kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>o</kbd> <kbd>gqas</kbd></kbd>
enters Normal mode, reformats the current sentence,<span class="fn">For an
explanation of <kbd>gqas</kbd> refer to the <a
href="#selecting-text-with-motions">Selecting Text with Motions</a>
recipe.</span> then returns you to Insert mode.</p>
<p>If you create a new file, and just want to type, by all means go straight
into Insert mode and do so. All other times, though, stay in Normal mode. </p>
<p>For example, you want to find a paragraph you've written previously, and
reword it. In Normal mode you can either <a
href="#searching-for-any-word">search</a> for it (e.g. <tt>/Hobson
argued</tt>), or simply page through the file (e.g.
<kbd><kbd>&lt;Ctrl&gt;</kbd>-<kbd>F</kbd></kbd> to scroll downwards) to find
it. Once there, you can move to the section you're interested in using either
the <a href="#basic-navigation">basic movement
commands</a> or <a href="#navigating-text-files">text objects</a>. You can
now use <i>text objects</i> again to select something and change it. For
example <kbd>caw</kbd> deletes the current word and puts you into Insert mode
to change it. Once you have done so, hit <kbd>&lt;Esc&gt;</kbd> again to
return to Normal mode. </p>
Something went wrong with that request. Please try again.