免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
楼主: projl
打印 上一主题 下一主题

《Learning the vi editor》 [复制链接]

论坛徽章:
0
161 [报告]
发表于 2008-06-11 15:25 |只看该作者
The man page for nvi.

The vi Tutorial

This document is a tutorial introduction to editing with vi.

The ex Reference Manual

The reference manual for ex. This manual is the original one for ex; it is a
bit out-of-date with respect to the facilities in nvi.

Also included are ASCII files that document some of the nvi internals, and provide
a list of features that should be implemented, and files that can be used as an
online tutorial to vi.

The actual online help built in to nvi is minimal, consisting of two commands,
:exusage and :viusage. These commands provide one-line summaries of each
ex and vi command. This is usually sufficient to remind you about how something
works, but not very good for learning about new or obscure features in nvi.

You can give a command as an argument to the :exusage and :viusage
commands, in which case nvi will display the help just for that command. nvi
prints one line explaining what the command does, and a one-line summary of
the command's usage.

9.4 Initialization
If the -s or "-" options have been specified, then nvi will bypass all initializations.
Otherwise, nvi performs the following steps:

1.
Read and execute the file /etc/vi.exrc. It must be owned either by root or
by you.
2.
Execute the value of the NEXINIT environment variable if it exists,
otherwise use EXINIT if it exists. Only one will be used, not both. Bypass
executing $HOME/.nexrc or $HOME/.exrc.
3.
If $HOME/.nexrc exists, read and execute it. Otherwise, if $HOME/.exrc
exists, read and execute it. Only one will be used.
4.
If the exrc option has been set, then look for and execute either ./.nexrc if
it exists, or ./.exrc. Only one will be used.
nvi will not execute any file that is writable by anyone other than the file's owner.

The nvi documentation suggests putting common initialization actions into your
.exrc file (i.e., options and commands for UNIX vi), and having your .nexrc file
execute :source .exrc before or after the nvi-specific initializations.

9.5 Multiwindow Editing
To create a new window in nvi, you use a capitalized version of one of the ex
editing commands: Edit, Fg, Next, Previous, Tag or Visual. (As usual, these
commands can be abbreviated.) If your cursor is in the top half of the screen, the
new window is created on the bottom half, and vice versa. You then switch to
another window with CTRL-W:

论坛徽章:
0
162 [报告]
发表于 2008-06-11 15:25 |只看该作者
<preface id="VI6-CH-0"
>
<title>Preface </title>


<para>
Text editing is one of the most common uses of any computer system,
and
<command>vi</command> is one of the most useful standard text editors
on your system.
With <command>vi</command> you can create new files, or edit any
existing
UNIX text file.
</para>


ch00.sgm: unmodified: line 1

# Makefile for vi book
#
# Arnold Robbins

CHAPTERS = ch00_6.sgm ch00_5.sgm ch00.sgm ch01.sgm ch02.sgm ch03.sgm\
ch04.sgm ch05.sgm ch06.sgm ch07.sgm ch08.sgmAPPENDICES = appa.sgm appb.sgm appc.sgm appd.sgm

POSTSCRIPT = ch00_6.ps ch00_5.ps ch00.ps ch01.ps ch02.ps ch03.ps \
ch04.ps ch05.ps ch06.ps ch07.ps ch08.ps \

Makefile: unmodified: line 1

This example shows nvi editing two files, ch00.sgm and Makefile. The split screen
is the result of typing nvi ch00.sgm followed by :Edit Makefile. The last line of
each window acts as the status line, and is where colon commands are executed
for that window. The status lines are highlighted in reverse video.

The windowing ex mode commands and what they do are described in Table 9.1.

Table 9.1. nvi Window Management Commands
Command Function
bg Hide the current window. It can be recalled with the fg and Fgcommands.
di[splay]
b[uffers]
Display all buffers, including named, un-named, and numeric
buffers.
di[splay]
s[creens]
Display the filenames of all backgrounded windows.
Edit
filename Edit filename in a new window.
Edit /tmp Create a new window editing an empty buffer. /tmp is interpreted
specially to create a new temporary file.
fg filename Uncover filename into the current window. The previous file moves
to the background.
Fg filename Uncover filename in a new window. The current window is split,
instead of redistributing the screen space among all open windows.
Next Edit the next file in the argument list in a new window.
Previous Edit the previous file in the argument list in a new window. (The
corresponding previous command, which moves back to the

论坛徽章:
0
163 [报告]
发表于 2008-06-11 15:26 |只看该作者
previous file, exists in nvi; it is not in UNIX vi.)
resize
卤nrows
Increase or decrease the size of the current window by nrows
rows.
Tagtagstring Edit the file containing tagstring in a new window.

The CTRL-W command cycles between windows, top to bottom. The :q and ZZ
commands exit the current window.

You may have multiple windows open on the same file. Changes made in one
window are reflected in the other, although changes made in nvi's insert mode
are not seen in the other window until after you finalize the change by typing
ESC. You will not be prompted to save your changes until you issue a command
that would cause nvi to leave the last window open upon a file.

9.6 GUI Interfaces
nvi does not provide a graphical user interface (GUI) version.

9.7 Extended Regular Expressions
Extended regular expressions were introduced in Section 8.4. Here, we just
summarize the metacharacters that nvi provides. nvi also supports the POSIX
bracket expressions, [[:alnum:]], and so on.

You use :set extended to enable extended regular expression matching.

|

Indicates alternation. The left and right sides need not be just single
characters.

(...)

Used for grouping, to allow the application of additional regular expression
operators.

When extended is set, text grouped with parentheses acts like text
grouped in \(...\) in regular vi; the actual text matched can be retrieved
in the replacement part of a substitute command with \1, \2, etc. In this
case, \( represents a literal left parenthesis.

+

Matches one or more of the preceding regular expressions. This is either a
single character or a group of characters enclosed in parentheses.

?

Matches zero or one occurrence of the preceding regular expression.

{...}

论坛徽章:
0
164 [报告]
发表于 2008-06-11 15:26 |只看该作者
Defines an interval expression. Interval expressions describe counted
numbers of repetitions. In the description below, n and m represent
integer constants.

{ n}
Matches exactly n repetitions of the previous regular expression.

{ n,}

Matches n or more repetitions of the previous regular expression.

{ n, m}

Matches n to m repetitions.

When extended is not set, nvi provides the same functionality with \{ and

\}.

As might be expected, when extended is set, you should precede the above
metacharacters with a backslash in order to match them literally.

9.8 Improvements for Editing
This section describes the features of nvi that make simple text editing easier and
more powerful.

9.8.1 Command-Line History and Completion
nvi saves your ex command lines, and makes it possible to edit them for
resubmission.

This facility is controlled with the cedit option.

When you type the first character of this string on the colon command line, nvi
opens a new window on the command history that you can then edit. When you
hit RETURN on any given line, nvi executes that line. ESC is a good choice for this
option. (Use ^V ^[ to enter it.)

Because the RETURN key actually executes the command, be careful to use either

the j or keys to move down from one line to the next.

In addition to being able to edit your command line, you can also do filename
expansion. This feature is controlled with the filec option.

When you type the first character of this string on the colon command line, nvi
treats the blank delimited word in front of the cursor as if it had an * appended to
it and does shell-style filename expansion. ESC is also a good choice for this
option.[4] (Use ^V ^[ to enter it.) When this character is the same as for the
cedit option, the command-line editing is performed only when it is entered as
the first character on the colon command line.

论坛徽章:
0
165 [报告]
发表于 2008-06-11 15:27 |只看该作者
[4] Although the nvi documentation indicates that TAB is another common choice, we could not get that to
work. In practice, using ESC for both options works well.
It is easiest to set these options in your .nexrc file:

set cedit=^[
set filec=^[

9.8.2 Tag Stacks
Tag stacking is described in Section 8.5.3. nvi's tag stack is the simplest of the
four clones. Table 9.2 and Table 9.3 show the commands it uses.

Table 9.2. nvi Tag Commands
Command Function
di[splay]
t[ags]
Display the tag stack.
ta[g][!]
tagstring
Edit the file containing tagstring as defined in the tags file. The !
forces nvi to switch to the new file if the current buffer has been
modified but not saved.
Ta[g][!]
tagstring Just like :tag, except that the file is edited in a new window.
tagp[op][!]
tagloc
Pop to the given tag, or to the most recently used tag if no tagloc
is supplied. The location may be either a filename of the tag of
interest or a number indicating a position in the stack.
tagt[op][!] Pop to the oldest tag in the stack, clearing the stack in the
process.
Table 9.3. nvi Command Mode Tag Commands
Command Function
^]
Look up the location of the identifier under the cursor in the tags file,
and move to that location. The current location is automatically pushed
onto the tag stack.
^T Return to the previous location in the tag stack, i.e., pop off one
element.
You can set the tags option to a list of file names where nvi should look for a tag.
This provides a simplistic search path mechanism. The default value is "tags/var/db/libc.tags /sys/kern/tags", which on a 4.4BSD system looks in the
current directory, and then in the files for the C library and the operating system
source code.

The taglength option controls how many characters in a tagstring are significant.
The default value of zero means to use all the characters.

nvi behaves like vi; it uses the "word" under the cursor starting at the current
cursor position. If your cursor is on the i in main, nvi will search for the identifier
in, not main.

nvi relies on the traditional tags file format. Unfortunately, this format is very
limited. In particular, it has no concept of programming language scope, which

论坛徽章:
0
166 [报告]
发表于 2008-06-11 15:28 |只看该作者
allows the same identifier to be used in different contexts to mean different
things. The problem is exacerbated by C++, which explicitly allows function name
overloading, i.e., the use of the same name for different functions.

nvi gets around the tags file limitations by using a different mechanism entirely:
the cscope program. cscope is a proprietary but relatively inexpensive program
available from the Bell Labs Software Toolchest. It reads C source files and builds
a database describing the program. nvi provides commands that query the
database and allow you to process the results. Because cscope is not universally
available, we do not cover its use here. Details of the nvi commands are provided
in the nvi documentation.

The extended tags file format produced by Exuberant ctags does not produce any
errors with nvi 1.79; however, nvi does not take advantage of this format either.

9.8.3 Infinite Undo
In vi, the dot (.) command generally acts as the "do again" command; it repeats
the last editing action you performed, be it a deletion, insertion, or replacement.

nvi generalizes the dot command into a full "redo" command, applying it even if
the last command was u for "undo."

Thus, to begin a series of "undo" commands, first type a u. Then, for each . (dot)
that you type, nvi will continue to undo changes, moving the file progressively
closer to its original state.

Eventually, you will reach the initial state of your file. At that point, typing . will
just ring the bell (or flash the screen). You can now begin redoing by typing u to
"undo the undos" and then using . to reapply successive changes.

nvi does not allow you to provide a count to either the u or . command.

9.8.4 Arbitrary Length Lines and Binary Data
nvi can edit files with arbitrary length lines and with an arbitrary number of lines.

nvi automatically handles binary data. No special command-line options or ex
options are required. You use ^X followed by one or two hexadecimal digits to
enter any 8-bit character into your file.

9.8.5 Incremental Searching
As mentioned in Section 8.6.4, you enable incremental searching in nvi using
:set searchincr.

The cursor moves through the file as you type, always being placed on the first
character of the text that matches.

论坛徽章:
0
167 [报告]
发表于 2008-06-11 15:28 |只看该作者
9.8.6 Left-Right Scrolling
As mentioned in Section 8.6.5, you enable left-right scrolling in nvi using :set
leftright. The value of sidescroll controls the number of characters by which
nvi shifts the screen when scrolling left to right.

9.9 Programming Assistance
nvi does not provide specific programming assistance facilities.

9.10 Interesting Features
nvi is the most minimal of the clones, without a large number of additional
features that have not yet been covered. Yet it does have several important
features worthy of mention.

Internationalization support

Most of the informational and warning messages in nvi can be replaced
with translations into a different language, using a facility known as a
"message catalog." nvi implements this facility itself, using a
straightforward mechanism documented in the file catalog/README in the
nvi distribution. Message catalogs are provided for Dutch, English, French,
German, Russian, Spanish, and Swedish.

Arbitrary buffer names

Historically, vi buffer names are limited to the 26 characters of the
alphabet. nvi allows you to use any character as a buffer name.

Special interpretation of /tmp

For any ex command that needs a filename argument, if you use the
special name /tmp, nvi will replace it with the name of a unique temporary
file.

9.11 Sources and Supported
Operating Systems
nvi can be obtained from http://www.bostic.com/vi . This is a web page from
which you can download the current version, and also ask to be added to a
mailing list that is notified about new versions of nvi and/or new features.

The source code for nvi is freely distributable. The licensing terms are described
in the LICENSE file in the distribution, and they permit distribution in source and
binary form.

nvi builds and runs under UNIX. It also can be built to run under LynxOS 2.4.0,
and possibly later versions. It may build and run on other POSIX compliant
systems as well, but the documentation does not contain a specific list of known
operating systems.

论坛徽章:
0
168 [报告]
发表于 2008-06-11 15:29 |只看该作者
Compiling nvi is straightforward. Retrieve the distribution via ftp. Uncompress
and untar it, run the configure program, and then run make.

$ gzip -d < nvi.tar.gz | tar -xvpf
..
.
$ cd nvi-1.79; ./configure
..
.
$ make
..
.


nvi should configure and build with no problems. Use make install to install it.

Should you need to report a bug or problem in nvi, the person to contact is Keith
Bostic, at bostic@bostic.com .

论坛徽章:
0
169 [报告]
发表于 2008-06-11 15:29 |只看该作者
Chapter 10. elvis

elvis was written and is maintained by Steve Kirkendall. An earlier
version became the basis for nvi. This chapter was written using
elvis.

10.1 Author and History
With our thanks for his help, we'll let Steve Kirkendall give the history in his own
words:

I started writing elvis 1.0 after an early clone called stevie crashed on me,
causing me to lose a few hours' work and totally destroying my confidence in that
program. Also, stevie stored the edit buffer in RAM which simply wasn't practical
in Minix. So I started writing my own clone, which stored its edit buffer in a file.
And even if my editor crashed, the edited text could still be retrieved from that
file.

elvis 2.x is almost completely separate from 1.x. I wrote this, my second vi clone,
because my first one inherited too many limitations from the real vi, and from
Minix. The biggest change is the support for multiple edit buffers and multiple
windows, neither of which could be retrofitted into 1.x very easily. I also wanted
to shed the line-length limitation, and have online help written in HTML.

As to the name "elvis," Steve says that at least part of the reason he chose the
name was to see how many people would ask him why he chose the name![1] It is
also common for vi clones to have the letters "vi" somewhere in their names.

[1] In around eight years, I was only number four! A.R.
10.2 Important Command-Line Arguments
elvis is not typically installed as vi, though it can be. If invoked as ex, it operates
as a line editor and allows the Q command from vi mode to switch into ex mode.

elvis has a number of command-line options. The most useful are described here:

-a

Load each file named on the command line into a separate window.

-r

Perform recovery after a crash.

-R

Start editing each file in read-only mode.

论坛徽章:
0
170 [报告]
发表于 2008-06-11 15:30 |只看该作者
Start editing in input mode instead of in command mode. This may be
easier for novice users.

-s

Set the safer option for the whole session, not just execution of .exrc
files. This adds a certain amount of security, but should not necessarily be
trusted blindly. In elvis 2.1, this option is renamed -S, and (following the
POSIX standard) -s provides ex scripting.

-f filename

Use filename for the session file instead of the default name. Session files
are discussed below.

-G gui

Use the given interface. The default is the termcap interface. Other
choices include x11, win32, curses, open, and quit. Not all the interfaces
may be compiled into your version of elvis.

-c command

Execute command upon start-up. This is the POSIX version of the
historical +command syntax. (The old syntax is also accepted.)

-t tag

Start editing at the specified tag.

Output more verbose status information. Useful for diagnosing problems
with initialization files.

-?

Print a summary of the possible options.

10.3 Online Help and Other Documentation
elvis is very interesting in this department. The online help is comprehensive, and
written entirely in HTML. This makes is easy to view in your favorite Web
browser. elvis also has an HTML display mode (discussed below), making it easy
and pleasant to view the online help from within elvis itself.

When viewing HTML files, you use the tag commands (^] and ^T) to go to
different topics and then return, making it easy to browse the help files. We
applaud this innovation in online help.

Of course, elvis also comes with UNIX man pages.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP