slackware-current/slackbook/html/vi.html
Patrick J Volkerding 75a4a592e5 Slackware 13.37
Mon Apr 25 13:37:00 UTC 2011
Slackware 13.37 x86_64 stable is released!

Thanks to everyone who pitched in on this release: the Slackware team,
the folks producing upstream code, and linuxquestions.org for providing
a great forum for collaboration and testing.

The ISOs are off to be replicated, a 6 CD-ROM 32-bit set and a
dual-sided
32-bit/64-bit x86/x86_64 DVD.  Please consider supporting the Slackware
project by picking up a copy from store.slackware.com.  We're taking
pre-orders now, and offer a discount if you sign up for a subscription.

As always, thanks to the Slackware community for testing, suggestions,
and feedback.  :-)

Have fun!
2018-05-31 22:45:18 +02:00

199 lines
7.2 KiB
HTML

<!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>