BBS水木清华站∶精华区

发信人: corpus (corpora), 信区: Unix 
标  题: vi-faq2(fwd) 
日  期: Sun Sep  8 16:50:55 1996 
 
 
4.0 - What's online at the vi archives? 
 
  There is a FAQ posted frequently which gives a list of all the files 
that are online at the vi archive.  It also gives a list of addresses 
which mirror the vi archive.  The main address is alf.uib.no, but it is 
archived at many, many sites.  The vi-archive faq lists all of them. 
Please check that faq before ftping to it, as there is almost defiantly 
a closer and therefore faster site to you that the one in Norway. 
  A mirror site is available at:  cs.uwp.edu /pub/vi, and another at 
monu6.cc.monash.edu.au /pub/Vi. 
  The site has many, many files on vi, including a few clones.  It also 
has the UCB distribution of vi, and lots of useful macros.  Check it 
out. 
 
5.0 - Silly vi tricks, and silly macros 
 
  This section is for silly vi tricks, and silly macros.  Actually, any 
interesting vi tricks and macros are acceptable, as long as they are 
not too lengthy.  I will add any that are suggested to me that I think 
are reasonable. 
 
5.1 - Silly vi tricks 
 
  xp     This will delete the character under the cursor, and put it 
afterwards.  In other words, it swaps the location of two characters. 
  
  ddp    Similar to xp, but swapping lines. 
  
  uu     Undo and redo last change.  (This will take you to the last 
modification to the file without changing anything.) 
 
5.2 - Silly macros 
 
  Swap character and one vertically above: 
    map * kxjphxkP 
 
  Fold a line that's too long 
    map g $80|F r 
 
  Change case on most words 
    map v ywmno:s/./\~/g 
 
  Put `and' around the current word 
    map *` i`' 
  Put 'and' around the current word 
    map *' i'' 
  Put "and" around the current word 
    map *" i"" 
  Put `and' around the current word 
    map! `` `' 
 
  Split a line at the cursor, and put a > at the beginning of 
  the next line.  (For quoting Usenet, etc).  If word wrapping is 
  enabled, it might wrap the last word on the first line.   
    map g may0O`ay$:s/./ /g 
 
  Insert one character 
    map g i$^[r 
 
6.0 - Alphabetical vi quick reference 
 
  ... means that something needs to be specified before or after the 
  command, as appropriate.  This is normally a cursor movement  
keys (h,j,k,l,w,b, etc.) or a line number. 
 
  #  (where # is a number) following command n times...   
  :  go to ex-mode  
  )  next sentence  
  (  previous sentence  
  }  next paragraph  
  {  previous paragraph  
 ]]  next section  
 [[  previous section 
  0  beginning of line  
  $  end of line  
  ^  first non-whitespace character 
  +  first character of next line  
  -  first character of previous line  
(spacebar) next character  
(return) next line  
  /  search forward  
  ? search backward  
  %  find match of current parenthesis, brace, or bracket  
  ,  reverse direction of last f, F, t, or T  
  ;  repeat last f, F, t, or T 
  .  repeat last command 
  `  goto mark  
  '  goto beginning of line with mark  
 ``  return to previous mark or location before a search  
 ''  go to start of line of previous mark or location before search 
  ~  switch case of current character  
  "  store in register  
 !!  repeat last shell command 
  !  send next to command, replace output (eg  !}fmt passes the current 
       paragraph to the command fmt, and replaces the output with 
       whatever fmt returns.)  
 >>  shift paragraph one shiftwidth to the right  
 <<  shift paragraph one shiftwidth to the left  
 >%  shift until matching (, [, or { to the right  
 <%  shift until matching (, [, or { to the left 
  a  append after the current location  
  A  append at the end of the line 
 ^a  unused 
  b  beginning of previous word  
  B  beginning of previous word, ignore punctuation  
 ^b  scroll back one screen 
  c  change until...   
  C  change to end of line  
 ^c  ends insert mode, unused in command mode 
  d  delete until...   
  D  delete to end of line  
 ^d  scroll down half a window, moves to previous shiftwidth in insert 
       mode 
  e  end of word  
  E  end of word, ignore punctuation  
 ^e  scroll screen down one line 
  f  find...   
  F  find backward...   
 ^f  scroll forward one screen 
  g  unused  
  G  ...Goto  [defaults to end of file]  
 ^g  show status line 
  h  left  
  H  first line on screen  
 ^h  backspace in insert mode, left in command mode 
  i  insert before current location  
  I  insert before first non-whitespace character on line  
 ^i  tab in insert, unused in command 
  j  down  
  J  join next line with current line  
 ^j  down in command, create newline in insert 
  k  up  
  K  unused  
 ^k  unused 
  l  right  
  L  last line on screen  
 ^l  redraw screen 
  m  mark position into register  
  M  middle of screen  
 ^m  carriage return 
  n  repeat last search  
  N  repeat last search, reverse direction  
 ^n down in command 
  o  open line below current  
  O  open line above current  
 ^o  unused 
  p  put below current line  
  P  put above current line  
 ^p  up in command 
  q  unused  
  Q  quit and run ex  
 ^q  unused 
  r  replace current character  
  R  replace characters until insert mode is left  
 ^r  redraw screen in command mode 
  s  substitute  
  S  substitute entire line  
 ^s  unused 
  t  to...   
  T  backward to...   
 ^t  moves to next shiftwidth. 
  u  undo last change  
  U  undo changes to current line  
 ^u  scroll up half a window 
  v  unused  
  V  unused  
 ^v  unused 
  w  beginning of next word  
  W  beginning of next word, ignore punctuation  
 ^w  unused in command, in insert move back to beginning of previous 
       word 
  x  delete current character  
  X  delete previous character  
 ^x  unused 
  y  yank...   
  Y  yank current line  
 ^y  scroll screen up one line 
  z  reposition screen around line (Return to top of screen, . to  
       middle, - to bottom)  
 ZZ  write and quit  
 ^z  unused 
 
6.1 - Command mode input options ( : commands) 
 
  (Note: this is not a canonical list, just some of the more important 
ones.) 
 
 :r <file>       read <file> into current text  
 :r !<command>   read output from command <command> into current text  
 :nr <file>      read in at line number  
 :!<file>        run command, return  
 :sh             goto shell  
 :so <file>      read and execute commands from <file> 
 :x              write and quit  
 :wq             write and quit  
 :l1,l2w <file>  write between lines l1 and l2 to <file>.  If <file>  
                   is not specified, assume current.  If l1,l2 not  
                   specified, assume entire file (making it :w) 
 :w >> <file>    append to <file>.  May use line numbers 
 :w!             overwrite current file  
 :q              quit 
 :q!             quit, forget changes  
 :e <file>       edit <file> without leaving vi  
 :e!             forget changes since last write 
 :n              edit next file  
 :e +n <file>    edit <file> at line n, if no end, assume end of file  
 :n <files>      specify <files> as new list of files to edit  
 :e#             edit alternate file (if :e <file> is used, alternate is 
                   the original file) 
 :args           show files to be edited  
 :rew            rewind life of files to top  
 :map m n        create a macro (make m do n)  
 :map! m n       create an insert mode macro (make m do n)  
 :unmap m        destroy macro m  
 :unmap! m       destroy insert mode macro m  
 :ab <1> <2>     abbreviate - replace <1> with <2> whenever typed as  
                   a word 
 :unab <1>       unabbreviate <1>  
 :set <option>   set <option>... 
 
6.2 - set options 
 
The abbreviations in parenthesis may be used.  Syntax: 
 
  :set <option> <param>   (If <param> is expected)  
  Multiple options may be specified on one line.   
  :set <option>? displays the value of the <option>  
  :set all displays the value of all the options.   
For options without a value, set no<option> turns it off. 
 
Option:             Default:           What it does: 
 
autoindent (ai)     noai               Makes new lines automatically 
                                         indent to the position as the  
                                         line above or below 
autoprint (ap)      ap                 Display changes after each  
                                         command  
autowrite (aw)      noaw               Automatically save file  
                                         before :n, :!   
beautify (bf)       nobf               Ignore all control characters 
                                         during input (except tab,  
                                         newline, formfeed) 
directory= (dir=)   /tmp               Name of the directory to store  
                                         buffer  
edcompatible        noedcompatible     Use ed-like features on  
                                         substitute  
errorbells (eb)     errorbells         Sound bell on error 
exrc (ex)           noexrc             Allow .exrc files outside home  
                                         dir  
hardtabs= (ht=)     8                  Set boundary for hardware tabs  
ignore case (ic)    noic               Ignore case in regex expressions  
lisp                nolisp             Turn on lisp mode 
list                nolist             Display all tabs, end of lines 
magic               magic              Enable more regex expressions 
mesg                mesg               Allows mesgs to be sent to  
                                         terminal  
number (nu)         nonumber           Displays line numbers in file  
open                open               Allows open and visual 
optimize (opt)      optimize           Optimizes throughput of text by  
                                         not sending carriage returns  
                                         when printing text 
paragraphs= (para=) IPLPPPQPPLIbp      Sets the delimiters for { & } 
prompt              prompt             Command mode input gives : prompt  
readonly (ro)       noro               Cannot write unless ! is given   
redraw              noredraw           Redraw screen when edits are made  
remap               remap              Allows macros that point to other 
                                         macros 
report=             5                  Report changes if they effect > x 
                                         lines 
scroll              1/2 window         Amount of screen to scroll when 
                                         scroll down is received in 
                                         command mode.  Also, number of 
                                         lines printer by z.  (z prints 
                                         2*scroll) 
sections=           SHNHH HU           Defines end of section for [[  
                                         and ]]  
shell= (sh=)        /bin/sh            Default shell.  Uses SHELL 
                                         environment, if set 
shiftwidth= (sw=)   8                  Characters to shift when using 
                                         shift commands 
showmatch (sm)      nosm               Show matching {, }, (, ), [, or ]  
showmode            noshowmode         Shows which mode you are in. 
slowopen (slow)                        Do not update display  
                                         immediately after insert 
tabstop= (ts=)      8                  Sets tabstop length  
taglength= (tl=)    0                  Number of characters significant 
                                         for tags (0 means all  
                                         characters) 
tags=               tag, /usr/lib/tags Define pathname of files  
                                         containing tags. 
term=                                  Set the terminal type 
terse               noterse            Display shorter error messages 
timeout (to)        timeout            Keyboard maps timeout after one  
                                         second  
ttytype=                               Set the terminal type 
warn                warn               Display "No write since last  
                                         change" messages 
window= (w=)                           Number of lines in window in visual 
                                         mode 
wrapmargin= (wm=)   0                  Set the right margin.  Greater  
                                         than 0 will word wrap n spaces 
                                         from the edge of the screen 
wrapscan (ws)       ws                 Searches wrap around end of file 
writeany (wa)       nowa               Allow saving to any file 
 
7.0 - Setting up .exrc file 
 
  Any commands that can be used in command input mode ( : commands), 
may be used in a .exrc, which will load automatically whenever you 
start vi.  In addition, the source command (so), abbreviations (ab), 
and macros may be used.  There may not be any blank lines in your 
.exrc.  A " in the first column may be used to tell vi that what 
follows is a comment. 
 
7.1 - Sample .exrc file 
 
  This .exrc file is a real one.  Mine.  Because of that, it doesn't 
set as many options as one might wish it did to get a good idea of what 
may be used.  However, it should get the basic idea down, and it is 
quite straightforward. 
 
First, note that you do not need to specify the :, it is assumed. 
 
" set wordwrap 9 characters from the right 
set wm=9 
" show matching parenthesis.  When },), or ] is hit, show the opening 
" {,(, or [ that matches it. 
set sm 
" set the shell to be /usr/local/bin/tcsh 
set sh=/usr/local/bin/tcsh 
" a few abbreviations 
" this makes -l automatically become -Larry, and zidlle to be my 
" name and email address. 
ab zidlle E. Larry Lidz - ellidz@midway.uchicago.edu 
ab -l -Larry 
" uppercase V will run ispell -x (-x tells it not to save backups) on current 
" file 
map V :w 
" K will center the line...  (this doesn't work on SunOS -- ??) 
map K :s/^[     ]*// 
" v will reformat the current paragraph 
map v {0!}fmt 
" q runs a program to lock my terminal 
map q :!lock2 
" Splits a line in two at current cursor location, puts a > at the 
"beginning of the line - useful for Usenet/email 
map g may0O`ay$:s/./ /g 
 
8.0 - Bugs in vi 
 
  I'd like to say that vi is bug free, but unfortunatly, it's not. 
These bugs are bugs in the original vi, not necessarily in any of the 
different clones. 
   
  Macros for _ do not always work properly. 
 
9.0 - Glossary of terms 
 
  This glossary will be updated as people suggest terms that they do 
not understand.  Please let me know if you have any suggestions. 
 
  command mode  
    Command mode is the mode within vi where the user gives commands to 
vi.  (Including cursor movement commands, editing commands, etc.) 
 
  ed  
    A non-visual editor under unix. 
 
 <Esc>  
    The escape key.  A key on a keyboard normally marked by escape. 
Sometimes ^[ will work in its place.  If there is no escape key, 
sometimes the Meta key will work. 
 
  ex  
    An editor under unix, all commands preceded with : are passed to 
it. 
 
  insert mode  
    Insert mode is the mode within vi where text is inserted into the 
document. 
 
  macro  
    A macro is a shortcut key combination.  For example, a macro allows 
one to hit one letter and have it execute a few different commands. 
 
  open mode  
    Open mode is the mode that vi will start in if it cannot determine 
your terminal type, or if it believes you have a hardware or glass-tube 
terminal. 
 
  regular expressions (RegEx)  
    Regular expressions, commonly known as "RegEx" are a set of key 
combinations that are meant to allow people to have a large variety of 
control over what they are searching for.  RegEx is used a lot under 
Unix, and is common between many programs. 
 
  sed  
    Stream-line editor.  An editor that has no interface.  All commands 
are given from the command line. 
 
  vi  
    The editor to which this FAQ is dedicated. 
 
10.0 - Bibliography of Books that cover vi 
 
  The ULTIMATE GUIDE to the VI and EX Text Editors 
  Hewlett Packard Company (authors) 
  The Benjamin/Cummings Publishing Company, Inc. 
  ISBN 0-8053-4460-8 
 
  A PRACTICAL GUIDE TO THE UNIX SYSTEM 
  Mark G. Sobell 
  Benjamin Cummings Publisher 
 
  LEARNING THE VI EDITOR 
  Linda Lamb 
  O'Reilly & Associates 
  ISBN 0-937175-67-6 
 
  Please make suggestions as to what books are most useful for learning 
vi.  I will add books to this section as people suggest them to me. 
 
(C)opyright, E. Larry Lidz, 1994, 1995.  All Rights Reserved. 

 

BBS水木清华站∶精华区