summaryrefslogtreecommitdiffstats
path: root/slackbook/html/vi.html
blob: d5fbf29f948a9cd7c58a8256bdb0951ccd1e1971 (plain) (blame)
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org" />
<title>Vi</title>
<meta name="GENERATOR" content="Modular DocBook HTML Stylesheet Version 1.7" />
<link rel="HOME" title="Slackware Linux Essentials" href="index.html" />
<link rel="PREVIOUS" title="zip" href="archive-files-zip.html" />
<link rel="NEXT" title="Modes" href="vi-modes.html" />
<link rel="STYLESHEET" type="text/css" href="docbook.css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body class="CHAPTER" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#840084"
alink="#0000FF">
<div class="NAVHEADER">
<table summary="Header navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<th colspan="3" align="center">Slackware Linux Essentials</th>
</tr>

<tr>
<td width="10%" align="left" valign="bottom"><a href="archive-files-zip.html"
accesskey="P">Prev</a></td>
<td width="80%" align="center" valign="bottom"></td>
<td width="10%" align="right" valign="bottom"><a href="vi-modes.html"
accesskey="N">Next</a></td>
</tr>
</table>

<hr align="LEFT" width="100%" />
</div>

<div class="CHAPTER">
<h1><a id="VI" name="VI"></a>Chapter 16 Vi</h1>

<div class="TOC">
<dl>
<dt><b>Table of Contents</b></dt>

<dt>16.1 <a href="vi.html#VI-STARTING">Starting vi</a></dt>

<dt>16.2 <a href="vi-modes.html">Modes</a></dt>

<dt>16.3 <a href="vi-opening-files.html">Opening Files</a></dt>

<dt>16.4 <a href="vi-saving-files.html">Saving Files</a></dt>

<dt>16.5 <a href="vi-quitting-vi.html">Quitting vi</a></dt>

<dt>16.6 <a href="vi-configuration.html">vi Configuration</a></dt>

<dt>16.7 <a href="vi-keys.html">Vi Keys</a></dt>
</dl>
</div>

<p><tt class="COMMAND">vi</tt>(1) is the standard Unix text editing program, and while
mastering it is not as essential as it once was, is still a very rewarding goal. There
are several versions (or clones) of <tt class="COMMAND">vi</tt> available, including <tt
class="COMMAND">vi</tt>, <tt class="COMMAND">elvis</tt>, <tt class="COMMAND">vile</tt>,
and <tt class="COMMAND">vim</tt>. One of these is available on just about any version of
Unix, as well as on Linux. All of these versions include the same basic feature set and
commands, so learning one clone should make it easy to learn another. With the variety of
text editors included with Linux distributions and Unix variants these days, many people
no longer use <tt class="COMMAND">vi</tt>. Still, it remains the most universal text
editor across Unix and Unix work-alikes. Mastering <tt class="COMMAND">vi</tt> means you
should never be sitting at a Unix machine and not be comfortable with at least one
powerful text editor.</p>

<p><tt class="COMMAND">vi</tt> includes a number of powerful features including syntax
highlighting, code formatting, a powerful search-and-replace mechanism, macros, and more.
These features make it especially attractive to programmers, web developers, and the
like. System administrators will appreciate the automation and integration with the shell
that is possible.</p>

<p>On Slackware Linux, the default version of <tt class="COMMAND">vi</tt> available is
<tt class="COMMAND">elvis</tt>. Other versions - including <tt class="COMMAND">vim</tt>
and <tt class="COMMAND">gvim</tt> - are available if you've installed the proper
packages. <tt class="COMMAND">gvim</tt> is an X Window version of <tt
class="COMMAND">vim</tt> that includes toolbars, detachable menus, and dialog boxes.</p>

<div class="SECT1">
<h1 class="SECT1"><a id="VI-STARTING" name="VI-STARTING">16.1 Starting vi</a></h1>

<p><tt class="COMMAND">vi</tt> can be started from the command line in a variety of ways.
The simplest form is just:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">vi</kbd>
</pre>
</td>
</tr>
</table>

<div class="FIGURE"><a id="FIG-VI-VIM-SPLITEDIT" name="FIG-VI-VIM-SPLITEDIT"></a>
<p><b>Figure 16-1. A vi session.</b></p>

<p><img src="vi/vim-splitedit.png" /></p>
</div>

<p>This will start up <tt class="COMMAND">vi</tt> with an empty buffer. At this point,
you'll see a mostly blank screen. It is now in &#8220;command mode&#8221;, waiting for
you to do something. For a discussion of the various <tt class="COMMAND">vi</tt> modes,
see the <a href="vi-modes.html">Section 16.2</a>. In order to quit out of <tt
class="COMMAND">vi</tt>, type the following:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<kbd class="USERINPUT">:q</kbd>
</pre>
</td>
</tr>
</table>

<p>Assuming that there have been no changes to the file, this will cause <tt
class="COMMAND">vi</tt> to quit. If there have been changes made, it will warn you that
there have been changes and tell you how to disregard them. Disregarding changes usually
means appending an exclamation point after the &#8220;<b class="KEYCAP">q</b>&#8221; like
so:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<kbd class="USERINPUT">:q!</kbd>
</pre>
</td>
</tr>
</table>

<p>The exclamation point usually means to force some action. We'll discuss it and other
key combinations in further details later.</p>

<p>You can also start <tt class="COMMAND">vi</tt> with a pre-existing file. For example,
the file <tt class="FILENAME">/etc/resolv.conf</tt> would be opened like so:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd class="USERINPUT">vi /etc/resolv.conf</kbd>
</pre>
</td>
</tr>
</table>

<p>Finally, <tt class="COMMAND">vi</tt> can be started on a particular line of a file.
This is especially useful for programmers when an error message includes the line their
program bombed on. For example, you could start up <tt class="COMMAND">vi</tt> on line 47
of <tt class="FILENAME">/usr/src/linux/init/main.c</tt> like so:</p>

<table border="0" bgcolor="#E0E0E0" width="100%">
<tr>
<td>
<pre class="SCREEN">
<samp class="PROMPT">%</samp> <kbd
class="USERINPUT">vi +47 /usr/src/linux/init/main.c</kbd>
</pre>
</td>
</tr>
</table>

<p><tt class="COMMAND">vi</tt> will display the given file and will place the cursor at
the specified line. In the case where you specify a line that is after the end of the
file, <tt class="COMMAND">vi</tt> will place the cursor on the last line. This is
especially helpful for programmers, as they can jump straight to the location in the file
that an error occurred, without having to search for it.</p>
</div>
</div>

<div class="NAVFOOTER">
<hr align="LEFT" width="100%" />
<table summary="Footer navigation table" width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td width="33%" align="left" valign="top"><a href="archive-files-zip.html"
accesskey="P">Prev</a></td>
<td width="34%" align="center" valign="top"><a href="index.html"
accesskey="H">Home</a></td>
<td width="33%" align="right" valign="top"><a href="vi-modes.html"
accesskey="N">Next</a></td>
</tr>

<tr>
<td width="33%" align="left" valign="top"><tt class="COMMAND">zip</tt></td>
<td width="34%" align="center" valign="top">&nbsp;</td>
<td width="33%" align="right" valign="top">Modes</td>
</tr>
</table>
</div>
</body>
</html>