免费注册 查看新帖 |

Chinaunix

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

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

论坛徽章:
0
191 [报告]
发表于 2008-06-11 15:42 |只看该作者

论坛徽章:
0
192 [报告]
发表于 2008-06-11 15:43 |只看该作者
$ make
...

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

In elvis 2.0, on Linux systems using GCC, you
should recompile the file lp.c without optimization.
Otherwise, at least in our experience, elvis tends to
core dump when using the :lpr command to format
and print the contents of an edit buffer.

Should you need to report a bug or problem in elvis, the person to contact is
Steve Kirkendall, at kirkenda@cs.pdx.edu .

论坛徽章:
0
193 [报告]
发表于 2008-06-11 15:43 |只看该作者
Chapter 11. vim鈥攙i Improved

vim stands for "Vi Improved." It was written by Bram Moolenaar,
who continues to maintain it. Today, vim is perhaps the most widely
used vi clone, and there exists a separate Internet domain
(vim.org) dedicated to it. Various versions of vim were used for
most of the work updating this book; much of the later work was
done with Version 5.0. Version 5.1 became current as the updates
were finishing; this is mostly a bug fix release.

11.1 Author and History
This section is adapted from material supplied by Bram Moolenaar,
vim's author. We thank him.

Work on vim started when the author bought an Amiga computer.
Coming from the UNIX world, he started using a vi-like editor called
stevie. But it was far from perfect. Fortunately, it came with the
source code. This is where work on vim started. At first it was a
matter of making the editor more vi compatible and fixing bugs.
After a while the program became very usable, and vim Version

1.14 was published on Fred Fish disk 591 (a collection of free
software for the Amiga).
Other people began to use the program, liked it, and started helping
development. A port to UNIX was done, then later to MS-DOS and
other systems. vim became one of the most widely available vi
clones. More features were added gradually: multi-level undo,
multiwindowing, etc. Some features were unique to vim, but many
were inspired by other vi clones. The goal has always been to
provide the best for the user.

Today vim is one of the most full-featured of the vi-style editors
anywhere. The online help is extensive. (It is described in more
detail below.)

One of the more obscure features of vim is to be able to type from
right to left. This is useful for languages like Hebrew and Farsi. This
illustrates vim's versatility. In Version 5.0 the vi compatibility was
also improved, and the performance was further tuned. Being a
rock-stable editor, on which professional software developers can
rely, is another of vim's design goals. Crashing with vim is rare, and
when it happens you can recover your changes.

The development on vim continues. Plans for vim 6.0 include
support for folding (being able to hide part of the text, e.g., the
body of a function). The group of people helping to add features and

论坛徽章:
0
194 [报告]
发表于 2008-06-11 15:44 |只看该作者
port vim to more platforms is growing. The quality of the ports to
different computer systems is increasing. The MS-Windows version
will get dialogues and a file-selector. This opens up the hard-tolearn
vi commands to a large group of users.

11.2 Important Command-Line Arguments
vim looks at how it was invoked to decide how it should behave. If
invoked as ex, it will operate as a line editor. It also allows the Q
command from vi mode to switch into ex mode. If invoked as view,
it will start in vi mode, but mark each file initially as being read-
only.

When invoked as gvim or gview, vim will start the GUI version,
under X Windows or in whatever other graphical interface is
appropriate. If a leading r is prepended to any of the names, vim
enters "restricted" mode, where certain actions are disabled.

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

-c command

Execute command upon startup. This is the POSIX version of
the historical +command syntax, but vim is not limited to
positioning commands. (The old syntax is also accepted.) You
can give up to ten -c commands.

-R

Start in read-only mode, setting the readonly option.

-r

Recover specified files, or if no files are listed on the
command line, list all the files that can be recovered.

-s

Enter batch (script) mode. This is only for ex, and is intended
for running editing scripts. This is the POSIX version of the
historic "-" argument.

-b

Start in binary mode. This sets a few options that make it
possible to edit a binary file.

论坛徽章:
0
195 [报告]
发表于 2008-06-11 15:45 |只看该作者
-f
For the GUI version, stay in the foreground. This should be
used by programs that invoke vim and wait for it to finish,
such as mail handling programs.
-g
Start the GUI version of vim, if it has been compiled in.
-o [N]
Open N windows, if given, otherwise open one window for
each file argument.
-i viminfo
Read the given viminfo file for initialization, instead of the
default viminfo file.
-n
Do not create a swap file. Recovery will not be possible, but
this is useful for editing files on slow media, such as floppies.
-q filename
Treat filename as the "quick fix" file. This file should contain a
list of error messages that vim will use for navigating to the
location of each error in your program. Quick fix mode is
discussed in Section 11.9.1.
-u vimrc
Read the given vimrc file for initialization, and skip all other
normal initialization steps.
-U gvimrc
Read the given gvimrc file for GUI initialization, and skip all
other normal GUI initialization steps.
-Z
Enter restricted mode (same as having a leading r in the
name). You cannot start shell commands or suspend the
editor when this is in effect.

论坛徽章:
0
196 [报告]
发表于 2008-06-11 15:45 |只看该作者
The -i, -n, -u and -U options are discussed in more detail below.
There are several more options; the interested reader is referred to
the online documentation for the full details.

11.3 Online Help and Other Documentation
vim comes with extensive and comprehensive online help. This help
is comprised of over 50 ASCII text files, totalling almost 25,500
lines of text!

The online help is hypertextual in nature; you use the tag
commands ^] and ^T to follow a reference and to go back to a
previous position. If you have a color display, using the help with
syntax coloring is particularly pleasant and effective.

The hypertext format is unique to vim; however the doc directory
contains a Makefile and awk scripts that convert the files into HTML
for perusal with a Web browser. (The html display mode in elvis
works just fine. ) The point to start from would be help.html,
generated from help.txt, the starting point for the online help.

Also included, of course, is a UNIX man page for vim.

To start the help system, give the :help command. This splits the
screen. With no arguments, vim displays the help.txt file. With an
argument to :help, vim does its best to find the help on that topic.
In our experience, it does an excellent job. (This facility seems to
be built on top of the tags mechanism, which has been applied to
the text of the help files.)

11.4 Initialization
This section describes vim's initialization steps, including those
taken for the GUI versions of vim.

11.4.1 Initialization for All vim Invocations
vim performs the following initialization steps:

1. Set the shell and term options from the SHELL and TERM
environment variables, respectively. On MS-DOS and Win32,
use COMSPEC to set shell if SHELL is not set.
2. If -u was supplied, execute the given file, and skip the rest of
the startup file based initializations. The -s option has the
same effect for ex mode; only the -u option will be
interpreted. Use of -u NONE causes vim to skip all further
initializations.

论坛徽章:
0
197 [报告]
发表于 2008-06-11 15:46 |只看该作者
3. Execute the system-wide vimrc file. The exact path is set
when vim is compiled. A typical value is
/usr/local/share/vim/vimrc.
4. Execute instructions in the first place that exists of the
following four:
o
The environment variable VIMINIT.
o
The user vimrc file, $HOME/.vimrc under UNIX (or
Linux). The location will be different on non-UNIX
systems. If .vimrc does not exist, vim looks for _vimrc.
On the non-UNIX systems, the order is reversed.
o
The environment variable EXINIT.
o
The user exrc file, $HOME/.exrc. On non-UNIX systems,
_exrc is tried. However, in this case, vim only looks for
one or the other, not both.
5. If the exrc option has been set, then vim looks in the current
directory for the first file that exists of the following four. The
others are ignored.
o
.vimrc
o
_vimrc
o
.exrc
o
_exrc
On MS-DOS and Win32 systems, the _xxxrc files are looked
for before the .xxxrc files.

6. If they have not yet been set, the shellpipe and shellredir
options are initialized based on the value of the shell option.
The shellredir option is discussed in Section 11.9.1.
7. If -n was given on the command line, updatecount is set to
zero. (This option controls how often the swap file is updated.
The more often, the more the swap file is synchronized with
all your changes, but possibly with decreased performance.
Zero means never.)
8. If -b was supplied, set the appropriate options for editing
binary files.
9. Perform GUI initializations. See the next subsection.
10. If viminfo is set, read the file indicated there.
11.
If -q was supplied, read the named quick fix file. The
quick fix facility is described in Section 11.9.1.
12.
Open and fill all windows, as per the -o option. If -qwas supplied, go to the first error.
13.
Jump to the tag given by the -t option, if supplied.
Execute any commands given with -c.
That's a lot of steps. As in other areas, vim's extra facilities also
provide extra flexibility and customizability.

论坛徽章:
0
198 [报告]
发表于 2008-06-11 15:46 |只看该作者
As for nvi, you can place common initialization actions into your
.exrc file (i.e., options and commands for UNIX vi and/or the other
clones), and have your .vimrc file execute :source .exrc before or
after the vim-specific initializations.

The viminfo file is much like the elvis session file. It can be used to
save a large part of the state of your editing session in between
logins. The viminfo file stores the following items:

论坛徽章:
0
199 [报告]
发表于 2008-06-11 15:47 |只看该作者
<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.


ch00.sgm

# 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

The split screen is the result of typing vim ch00.sgm followed by :split
Makefile.

Unlike nvi and elvis, all windows share the bottom line of the screen for execution
of ex commands. However, the status line for each file displays [+] if that file has
been modified. Options control the use of reverse video versus highlighting for
the status line, as well as whether the bottom window even has one. By default,
the bottom window has a status line when there's more than one window.

Table 11.1 describes the most important vim window management commands.

Table 11.1. vim Window Management Commands
Command Function
[N]sp[lit]
[position]
[file]
Splits the current window into two. N is the height of the new
window. position indicates where in the file to position the cursor.
If file is given, edit it in the new window, instead of the current
file.
[N]new
[position]
[file]
Creates a new window, editing an empty buffer. If file is given,
edit it instead of the empty buffer. N and position are the same
as for :split.
[N]sv[iew]
[position]
[file]
Same as :split, but set the readonly option for the buffer.
q[uit][!]
Quit the current window (exit if given in the last window). If this
is the last window on a changed buffer, the command fails,
unless the ! is given, in which case the changes are lost. When
the hidden option is set, the buffer is not freed, even with !.
clo[se][!]
Close the current window. Setting the hidden option will just hide
an unsaved buffer; if not set, the command fails. If supplied, the
trailing ! forces the window to be closed, even if it is the last

论坛徽章:
0
200 [报告]
发表于 2008-06-11 15:47 |只看该作者
window and the buffer was modified.
hid[e]
Close the current window, if it is not the last one on the screen.
The buffer becomes hidden if this was the last window open upon
the buffer.
on[ly][!]
Make this window the only one on the screen. Other windows
with changes are not closed, unless hidden is set or ! is used. In
any case, changes are never lost; the other buffers become
hidden, but they are not discarded.
res[ize] [卤n] Increase or decrease the current window height by n.
res[ize] [n] Set the current window height to n if supplied, otherwise, set it
to the largest size possible without hiding the other windows.
qa[ll][!]
Exit vim. The ! forces an exit, even if some buffers have been
modified but not saved.
wqa[ll][!] Write all changed buffers and exit. The ! forces a write of
readonly buffers. vim will not exit if any buffer cannot be
written. xa[ll][!]
wa[ll][!]
Write all modified buffers that have filenames. The ! forces a
write of readonly buffers.
[N]sn[ext] Split the window and move to the next file in the argument list,
or to the Nth file if a count is supplied.
sta[g]
[tagname]
Split the window and then run the :tag command as appropriate
in the new window.

There are many more commands for managing the argument list and the list of
open buffers. For example, the :all command creates one window for each
command line argument. See the vim online help for details. We have included
just the most useful of the commands in the above table.

As vim has the most ex commands, so too it has the most vi mode commands, as
shown in Table 11.2. As with most vi commands, you can prefix many of the
windowing commands with a count.

Table 11.2. vim Window Commands from vi Mode
Command Function
^W s
^W S
^W ^S
Same as :split without a file argument. ^W ^S may not work on all
terminals.
^W n
^W ^N
Same as :new without a file argument.
^W ^
^W ^^
Perform :split #, split the window and edit the alternate file. With a
count, edit the nth buffer.
^W q^W ^Q
Same as the :quit command. ^W ^Q may not work on all terminals.
^W c Same as the :close command.
^W o
^W ^O
Like the nly command.
^W
<DOWN>
^W ^J
Move cursor to nth window below the current one. n is supplied as a
prefix argument.
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP