home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume6 / help / part2 / help.dir / vi / commands / funky.HLP < prev    next >
Encoding:
Text File  |  1986-11-30  |  2.2 KB  |  75 lines

  1.  
  2.     To help you learn vi a little better, here are some 
  3.     funky command sequences that will do powerful things
  4.     in vi.
  5.  
  6.     1)    Piping your buffer thru a command
  7.  
  8.       Let's say you want to quote something in a letter or
  9.       other text, by making it all upper-case.  
  10.       You could do this in vi command state:
  11.     
  12.         10!!tr 'a-z' 'A-Z'
  13.  
  14.       Another example: let's say you needed to sort a
  15.       buffer alphabetically.  You could use this sequence
  16.       in vi to pipe the whole buffer to sort(1) and back again.
  17.  
  18.         1G!Gsort -df    
  19.         
  20.  
  21.     2)    Pattern matching and replacement
  22.  
  23.       The general pattern-match-and-replacement capabilities
  24.       of ex(1) are excellent.  They even provide interactive
  25.       query-replace.
  26.  
  27.       Let's say you need replace the strings "XMACnnn' where 
  28.       'nnn' is a number, by 'ZMACROnnn' in almost every place
  29.       it occurs.  You could use this interactive replace to do
  30.       the job
  31.  
  32.         1,$s/XMAC\([0-9]*\)/ZMACRO\1/c
  33.  
  34.       Each time vi finds a candidate for replacement, it will 
  35.       display the line on which was found and you can type
  36.       "yes" or "no" to replace or not replace.  For more info
  37.       on regular-expression pattern-matching and area addressing,
  38.       see "The Ex Reference Manual".
  39.  
  40.  
  41.     3)    Macros      (Yes, really!)
  42.  
  43.       Vi has a limited macro facility that is part of ex(1).
  44.       The macros written using this facility can perform an
  45.       vi command, but have no parameters and do not nest.
  46.  
  47.       Macros are defined using the ":map" command.  The basic
  48.       syntax is:
  49.             :map lhs rhs
  50.  
  51.       The lhs should be a single character (such as 'E' or '+')
  52.       and may be a control character if quoted with ^V.  Let's
  53.       define a macro to start up an nroff paragraph.  The command
  54.       character will be 'P'.
  55.  
  56.             :map P oi.pp^V^[o
  57.  
  58.       You can learn more about macros in section 6.9 of
  59.       "An Introduction to Display Editing with Vi".
  60.  
  61.  
  62.     4)     Abbreviations
  63.  
  64.       You can define abbreviations with the ex command 'ab'.
  65.       For instance, to define "ax" as an abbreviation for
  66.       "AIRX project", you would do this:
  67.  
  68.         :ab ax AIRX project
  69.  
  70.       Abbreviations are different from macros in that they are
  71.       expanded in insert state, and they only work when the
  72.       lhs is a single word (i.e. if 'ax' were part of a longer
  73.       word it would be left alone).
  74.  
  75.