/
01_choosing_the_right_mode.html
64 lines (52 loc) · 2.71 KB
/
01_choosing_the_right_mode.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<h3 id="choosing-right-mode">Choosing the Right Mode</h3>
<h4>Problem</h4>
<p>You know that Vim has multiple modes of operation but aren't sure when to use
which one.</p>
<h4>Solution</h4>
<p>For practical purposes there are four modes:</p>
<dl>
<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
needed.</dd>
<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>
</dl>
<h4>Discussion</h4>
<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><Ctrl></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><Ctrl></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>
</blockquote>
<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><Ctrl></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><Esc></kbd> again to
return to Normal mode. </p>