免费注册 查看新帖 |

Chinaunix

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

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

论坛徽章:
0
251 [报告]
发表于 2008-06-11 16:17 |只看该作者
returned. This rather whimsical example from the macros.doc file should give you
a taste of the language's flavor:

~if &sequal %curplace "timespace vortex"

insert-string "First, rematerialize\n"
~endif
~if &sequal %planet "earth" ;If we have landed on earth...

~if &sequal %time "late 20th century" ;and we are thenwrite-message "Contact U.N.I.T."

~else
insert-string "Investigate the situation....\n"
insert-string "(SAY 'stay here Sara')\n"

~endif
~elseif &sequal %planet "luna" ;If we have landed on our neighbor...
write-message "Keep the door closed"

~else
setv %conditions @"Atmosphere conditions outside? "
~if &sequal %conditions "safe"

insert-string &cat "Go outside......" "\n"
insert-string "lock the door\n"

~else
insert-string "Dematerialize..try somewhen else"
newline

~endif
~endif

You can store these procedures into a numbered macro, or give them names that
can be bound to keystrokes. The above procedure is most useful when using the
Tardis vile port.
This more realistic example from Paul Fox runs grep, searching for the word
under the cursor in all C source files. It then puts the results in a buffer named
after the word, and sets things up so that the built-in error finder (^X ^X) will use
this output as its list of lines to visit. Finally, the macro is bound to ^A g. The
~force command allows the following command to fail without generating an
error message:

14 store-macro
set-variable %grepfor $identifieredit-file &cat "!egrep -n " &cat %grepfor " *.[ch]"
~force rename-buffer %grepfor
error-buffer $cbufname

~endm
bind-key execute-macro-14 ^A-g

Finally, the read-hook and write-hook variables can be set to names of
procedures to run after reading and before writing a file, respectively. This allows
you to do things similar to pre- and post-operation files in elvis and the
autocommand facility in vim.

The language is quite capable, including flow control and comparison features,
and variables that provide access to a large amount of vile's internal state. The
macros.doc file in the vile distribution describes the language in detail.

12.10.4 Miscellaneous Small Features
Several other, smaller features are worth mentioning:

论坛徽章:
0
252 [报告]
发表于 2008-06-11 16:17 |只看该作者
Piping into vile

If you make vile the last command in a pipeline, it will create a buffer
named [Standard Input] and edit that buffer for you. This is perhaps the
"pager to end all pagers."

Editing DOS files

When set to true, the dos option causes vile to strip carriage returns at the
end of a line in files when reading, and to write them back out again. This
makes it easy to edit DOS files on a UNIX or Linux system.

Text reformatting

The ^A f command reformats text, performing word wrapping on selected
text. It understands C and shell comments (lines with a leading * or #)
and quoted email (a leading >). It is similar to the UNIX fmt command, but
faster.

Formatting the information line

The modeline-format variable is a string which controls the way vile
formats the mode line. This is the line at the bottom of each window that
describes the buffer's status, such as its name, current major mode,
modification status, insert versus command mode, and so on.

The string consists of printf(3) style percent-sequences. For example, %b
for the buffer name, %m for the major mode, and %l for the line number if
ruler has been set. Characters in the string which are not part of a format
specifier are output verbatim.

vile has many other features. The vi finger-feel makes it easy to move to. The
programmability provides flexibility, and its interactive nature and use of defaults
is perhaps friendlier for the novice than traditional vi.

12.11 Sources and Supported
Operating Systems
The official WWW location for vile is
http://www.clark.net/pub/dickey/vile/vile.html . The ftp location is
ftp://ftp.clark.net/pub/dickey/vile/vile.tar.gz . The file vile.tar.gz is always a
symbolic link to the current version.

vile is written in ANSI C. It builds and runs on UNIX, VMS (with both VAX C and
DEC C), MS-DOS, Win32 console and Win32 GUI, and OS/2.

Compiling vile is straightforward. Retrieve the distribution via ftp or from the web
page. Uncompress and untar it, run the configure program, and then run make:

$ gzip -d < vile.tar.gz | tar -xvpf
...
$ cd vile-8.0; ./configure
...
$ make

论坛徽章:
0
253 [报告]
发表于 2008-06-11 16:18 |只看该作者
...

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

If you intend to use a Linux console and want
syntax coloring to work, you may wish to run
configure with the following option: --withscreen=
ncurses.
Should you need to report a bug or problem in vile, send email to the address
vile-bugs@foxharp.boston.ma.us . This is the preferred way to report bugs. If
necessary, you can contact Tom Dickey directly at dickey@clark.net .

论坛徽章:
0
254 [报告]
发表于 2008-06-11 16:19 |只看该作者
Appendix A. Quick Reference

This appendix lists vi commands and ex commands according to
their use.

Table A.1. Movement Commands
Command Function
Character
h,j,k,l Left, down, up, right ( , , , ).
Text
w,W,b,B Forward, backward by word.
e,E End of word.
),( Beginning of next, previous sentence.
},{ Beginning of next, previous paragraph.
]],[[ Beginning of next, previous section.
Lines
RETURN First non-blank character of next line.
0, $ First, last position of current line.
^ First non-blank character of current line.
+, First
non-blank character of next, previous line.
n| Column n of current line.
H Top line of screen.
M Middle line of screen.
L Last line of screen.
nH n (number) of lines after top line.
nL n (number) of lines before last line.
Scrolling
CTRL-F, CTRL-B Scroll forward, backward one screen.
CTRL-D, CTRL-U Scroll down, up one-half screen.
CTRL-E, CTRL-Y Show one more line at bottom, top of window.
z RETURN Reposition line with cursor: to top of screen.
z. Reposition line with cursor: to middle of screen.
z-Reposition line with cursor: to bottom of screen.
CTRL-L Redraw screen (without scrolling).
Searches
/pattern Search forward for pattern.
?pattern Search backward for pattern.
n, N Repeat last search in same, opposite direction.
/, ? Repeat previous search forward, backward.
fx Search forward for character x in current line.
Fx Search backward for character x in current line.
tx Search forward to character before x in current line.
Tx Search backward to character after x in current line.

论坛徽章:
0
255 [报告]
发表于 2008-06-11 16:19 |只看该作者
; Repeat previous current-line search.
, Repeat previous current-line search in opposite direction.
Line number
CTRL-G Display current line number.
nG Move to line number n.
G Move to last line in file.
:n Move to line n in file.
Marking position
mx Mark current position as x.
`x Move cursor to mark x.
` ` Return to previous mark or context.
'x Move to beginning of line containing mark x.
'' Return to beginning of line containing previous mark.
Table A.2. Editing Commands
Command Function
Insert
i, a Insert text before, after cursor.
I, A Insert text before beginning, after end of line.
o, O Open new line for text below, above cursor.
Change
r Replace character.
cw Change word.
cc Change current line.
cmotion Change text between the cursor and the target of motion.
C Change to end of line.
R Type over (overwrite) characters.
s Substitute: delete character and insert new text.
S Substitute: delete current line and insert new text.
Delete, move
x Delete character under cursor.
X Delete character before cursor.
dw Delete word.
dd Delete current line.
dmotion Delete text between the cursor and the target of motion.
D Delete to end of line.
p, P Put deleted text after, before cursor.
"np Put text from delete buffer number n after cursor (for last nine
deletions).
Yank
yw Yank (copy) word.
yy Yank current line.
"ayy Yank current line into named buffer a (a-z). Uppercase names
append text.
ymotion Yank text between the cursor and the target of motion.

论坛徽章:
0
256 [报告]
发表于 2008-06-11 16:20 |只看该作者
p, P Put yanked text after, before cursor.
"aP Put text from buffer a before cursor (a-z).
Other commands
. Repeat last edit command.
u, U Undo last edit; restore current line.
J Join two lines.
ex edit
commands
:d Delete lines.
:m Move lines.
:co or :t Copy lines.
:.,$d Delete from current line to end of file.
:30,60m0 Move lines 30 through 60 to top of file.
:.,/pattern/co$ Copy from current line through line containing pattern to end
of file.
Table A.3. Exit Commands
Command Function
ZZ Write (save) the file if modified, and quit file.
Write (save) the file if modified, and quit file.
:wq Write (save) the file unconditionally, and quit file.
:w Write (save) file.
:w! Write (save) file, overriding protection.
:30,60w newfile Write from line 30 through line 60 as newfile.
:30,60w>> file Write from line 30 through line 60 and append to file.
:w %.new Write current buffer named file as file.new.
:q Quit file.
:q! Quit file, overriding protection.
Q Quit vi and invoke ex.
:e file2 Edit file2 without leaving vi.
:r newfile Read contents of newfile into current file.
:n Edit next file.
:e! Return to version of current file at time of last write (save).
:e # Edit alternate file.
:vi Invoke vi editor from ex.
: Invoke one ex command from vi editor.
% Current filename (substitutes into ex command line).
# Alternate filename (substitutes into ex command line).
Table A.4. Solaris vi 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. If tag stacking is enabled, 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.

论坛徽章:
0
257 [报告]
发表于 2008-06-11 16:20 |只看该作者
Table A.5. Command-Line Options
Command Function
vi file Invoke vi editor on file.
vi file1 file2 Invoke vi editor on files sequentially.
view file Invoke vi editor on file in read-only mode.
vi -R file Invoke vi editor on file in read-only mode.
vi -r file Recover file and recent edits after a crash.
vi -t tag Look up tag and start editing at its definition.
vi -w n Set the window size to n; useful over a slow connection.
vi + file Open file at last line.
vi +n file Open file directly at line number n.
vi -c command
file
Open file, execute command, which is usually a search
command or line number (POSIX).
vi +/pattern
file Open file directly at pattern.
ex file Invoke ex editor on file.
ex -file <
script
Invoke ex editor on file, taking commands from script; suppress
informative messages and prompts.
ex -s file <
script
Invoke ex editor on file, taking commands from script; suppress
informative messages and prompts (POSIX).
Table A.6. Other ex Commands
Command Function
Abbreviations [A]
:map x sequence Define keystroke x as a command sequence. x can be
multiple characters.
:map! x sequence Define x as command sequence for insert mode.
:unmap x Disable the map x.
:unmap! x Disable the insert mode map x.
:ab abbr phrase Abbreviate phrase as abbr; when abbr is typed in insert
mode, it expands to full words or phrases.
:unab abbr Disable abbreviation abbr.
Customizing
environment: [A]
:set option Activate option.
:set option=value Assign value to option.
:set nooption Deactivate option.
:set Display options set by user.
:set all Display list of all current option settings, both default and
those set by the user.
:set option? Display value of option.
Accessing UNIX
:sh Invoke shell.
^D Return to editor from shell.
:! command Give UNIX command.
:n,m! command Filter lines n to m through UNIX command.

论坛徽章:
0
258 [报告]
发表于 2008-06-11 16:21 |只看该作者
:r !command Read output of UNIX command into current file.
[A] In .exrc files, omit the colon at the start of ex commands.

论坛徽章:
0
259 [报告]
发表于 2008-06-11 16:21 |只看该作者
Appendix B. ex Commands

This appendix describes the syntax of ex commands and then
presents an alphabetical list of ex commands.

B.1 Command Syntax
To enter an ex command from vi, use this form:

:[address]command[options]

address is the line number or range of lines that are the object of
command. If no address is given, the current line is (usually) the
object of the command.

B.1.1 Address Symbols
In ex command syntax, address can be specified in any of the forms
shown in Table B.1.

Table B.1. ex Address Syntax
Address Includes
1,$ All lines in the file
x,y Lines x through y
x;y Lines x through y, with current line reset to x
0 Top of file
. Current line
n Absolute line number n
$ Last line
% All lines; same as 1,$
x-n n lines before x
x+n n lines after x
-[n] One or n lines previous
+[n] One or n lines ahead
'x Line marked with x
'' Previous mark
/pat/ or ?pat? Ahead or back to line where pat matches
B.1.2 Option Symbols
In ex command syntax, options might be any of the following:

!

论坛徽章:
0
260 [报告]
发表于 2008-06-11 16:22 |只看该作者
Indicates a variant form of the command, overriding the
normal behavior.

count

The number of times the command is to be repeated. count
cannot precede the command, because a number preceding
an ex command is treated as a line address. d3 deletes three
lines beginning with the current line; 3d deletes line 3.

file

The name of a file that is affected by the command. % stands
for current file; # stands for previous file.

B.2 Alphabetical List of Commands
In this section, the full name of the ex command is listed as the
keyword. To the right of or below each keyword is the syntax, using
the shortest abbreviation possible for that command. A brief
description follows the syntax.

abbrev

ab [string text]

Define string when typed to be translated into text. If string
and text are not specified, list all current abbreviations.

append

[address] a[!]

text

.

Append text at specified address, or at present address if one
is not specified. Add a ! to switch the autoindent setting that
will be used during input. That is, if autoindent was enabled,
! disables it.

args

ar
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP