  Vim Color Editor HOW-TO (Vi Improved with syntax color high-
  lighting)
  Al Dev (Alavoor Vasudevan)        alavoor@yahoo.com
  v4.0, 31 December 1999

  This document is a guide to very quickly setup Vim color editor on
  Linux or Unix systems. The information here will improve the prodcu-
  tivity of programmer since Vim editor supports syntax color highlight-
  ing and bold fonts which improves the "readability" of program code.
  Programmer's productivity improves 2 to 3 times with color editor like
  Vim.  The information in this document applies to all operating sytems
  where Vim works that is - Windows 95/NT and all flavors of Unix like
  Linux, Solaris, HPUX, AIX, SCO, Sinix, BSD, SCO, etc..
  ______________________________________________________________________

  Table of Contents


















































  1. Introduction

     1.1 Install Vim on Redhat Linux
     1.2 Install Vim on GNU Debian Linux
     1.3 Install Vim on Unixes
     1.4 Install Vim on Microsoft Windows 95/NT

  2. Setup gvim init files

     2.1 Sample gvimrc file
     2.2 Xdefaults parameters

  3. Color Syntax init files

  4. VIM Usage

  5. Vi companions

     5.1 Ctags for ESQL
     5.2 Ctags for Javascript programs, Korn, Bourne shells
     5.3 Debugger gdb

  6. Online VIM help

  7. Vim Home page and Vim links

  8. Vim Tutorial

     8.1 Vim Hands-on Tutorial
     8.2 Vi Tutorials on Internet

  9. Vi Tutorial

     9.1 Cursor Movement Commands
     9.2 Repeat Counts
     9.3 Deleting Text
     9.4 Changing Text
     9.5 Yanking (Copying) Text
     9.6 Filtering text
     9.7 Marking Lines and Characters
     9.8 Naming Buffers
     9.9 Substitutions
     9.10 Miscellaneous "Colon Commands"
     9.11 Setting Options
     9.12 Key Mappings
     9.13 Editing Multiple Files
     9.14 Final Remarks

  10. Vim Reference Card

     10.1 Vi states
     10.2 Shell Commands
     10.3 Setting Options
     10.4 Notations used
     10.5 Interrupting, cancelling
     10.6 File Manipulation
     10.7 Movement
     10.8 Line Positioning
     10.9 Character positioning
     10.10 Words, sentences, paragraphs
     10.11 Marking and returning
     10.12 Corrections during insert
     10.13 Adjusting the screen
     10.14 Delete
     10.15 Insert, change
     10.16 Copy and Paste
     10.17 Operators (use double to affect lines)
     10.18 Search and replace
     10.19 General
     10.20 Line Editor Commands
     10.21 Other commands

  11. Other Formats of this Document



  ______________________________________________________________________

  11..  IInnttrroodduuccttiioonn

  Vim editor stands for 'Vi Improved'. Vi is the most popular and
  powerful editor in the Unix world. The VVii is a abbreviation for
  "VViisual" editor.  In olden days, the first editor on this planet was a
  line editor called 'ed' (and 'ex'). The VViisual editor like Vi was a
  vast improvement over line editors like 'ed' (or 'ex'). The editors
  'ed' and 'ex' are still available on Linux, see 'man ed' and 'man ex'.

  A good editor will improve the productivity of the programmer. Vim
  supports color syntax highlighting of program code and also emphasises
  using different fonts like normal, bold or italics. The color editor
  like Vim will improve the pprroodduuccttiivviittyy of programming by 22 ttoo 33
  ttiimmeess!! Programmers can read the code much more rapidly as the code
  syntax is colored and highlighted.

  11..11..  IInnssttaallll VViimm oonn RReeddhhaatt LLiinnuuxx

  To use Vim install the following RPM packages on Redhat Linux -

  ______________________________________________________________________
          rpm -i vim*.rpm
  OR do this -
          rpm -i vim-enhanced*.rpm
          rpm -i vim-X11*.rpm
          rpm -i vim-common*.rpm
          rpm -i vim-minimal*.rpm
  ______________________________________________________________________


  You can see the list of files the vim rpm installs by -

  ______________________________________________________________________

          rpm -qa | grep ^vim | awk '{print "rpm -ql " $1 }' | /bin/sh | less
  ______________________________________________________________________


  and browse output using j,k, CTRL+f, CTRL+D, CTRL+B, CTRL+U or using
  arrow keys, page up/down keys.  See 'man less'.

  11..22..  IInnssttaallll VViimm oonn GGNNUU DDeebbiiaann LLiinnuuxx

  To install Vim on Debian Linux (GNU Linux), login as root and when
  connected to internet type -

  ______________________________________________________________________
  apt-get install vim vim-rt
  ______________________________________________________________________


  It will go download the lastest version of vim, install it, configure
  it, and erase the .deb file it downloaded. The first package listed is
  vim, the standard editor, compiled with X11 support, vim-rt is the vim
  runtime, it holds all the syntax and help files.


  11..33..  IInnssttaallll VViimm oonn UUnniixxeess

  For other flavors of unixes like Solaris, HPUX, AIX, Sinix, SCO
  download the source code file

  ______________________________________________________________________

          zcat vim.tar.gz | tar -xvf -
          cd vim-5.5/src
          ./configure --enable-gui=motif
          make
          make install
  ______________________________________________________________________




  11..44..  IInnssttaallll VViimm oonn MMiiccrroossoofftt WWiinnddoowwss 9955//NNTT

  For Windows 95/NT, download the zip file and install clicking on
  setup.  Get the zip file from -

  +o  The home page of vim is at  <http://www.vim.org>

  +o  Mirror site in US is at  <http://www.us.vim.org>


  22..  SSeettuupp ggvviimm iinniitt ffiilleess

  To enable the syntax color highlighting you MUST copy the gvimrc file
  to your home directory. This will also put the "Syntax" Menu with gvim
  command.  You can click on Syntax Menu and select appropriate
  languages like C++, Perl, Java, SQL, ESQL etc..

  ______________________________________________________________________
  cd $HOME
  cp /usr/doc/vim-common-5.3/gvimrc_example  ~/.gvimrc
  ______________________________________________________________________


  Comment lines in .gvimrc begin with double-quotes (").  You can cus-
  tomize gvim by editing the file $HOME/.gvimrc and put the following
  lines -

  ______________________________________________________________________
  " This line is a comment .... one which begins with double-quotes
  " The best is the bold font, try all of these and pick one....
  set guifont=8x13bold
  "set guifont=9x15bold
  "set guifont=7x14bold
  "set guifont=7x13bold
  "
  " Highly recommended to set tab keys to 4 spaces
  set tabstop=4
  set shiftwidth=4
  "
  " The opposite is 'set wrapscan' while searching for strings....
  set nowrapscan
  "
  " The opposite is set noignorecase
  set ignorecase
  ______________________________________________________________________

  It is vveerryy  ssttrroonnggllyy recommended that you set the _t_a_b_s_t_o_p to 4 and
  _s_h_i_f_t_w_i_d_t_h to 4.  The _t_a_b_s_t_o_p is number spaces TAB key will put while
  editing with gvim. The _s_h_i_f_t_w_i_d_t_h is the number spaces the lines will
  be shifted with ">>" or "<<"  vi commands (Press twice "greater than"
  and "less than" keys on keyboard). Refer to Vi tutorials ``'' for more
  details.

  22..11..  SSaammppllee ggvviimmrrcc ffiillee

  You can change the settings like color, bold/normal fonts in your
  $HOME/.gvimrc file.  It is vveerryy ssttrroonnggllyy recommended that you set the
  background color to _l_i_g_h_t_y_e_l_l_o_w or _w_h_i_t_e with _b_l_a_c_k foreground.
  Ergonomics says that best background color is _l_i_g_h_t_y_e_l_l_o_w or _w_h_i_t_e
  with _b_l_a_c_k foreground. Hence change the variable 'guibg' in your
  $HOME/.gvimrc file as follows:

  ______________________________________________________________________
          highlight Normal guibg=lightyellow
  ______________________________________________________________________



  The sample gvimrc from /usr/doc/vim-common-5.3/gvimrc_example is as
  follows:










































  ______________________________________________________________________
  " Vim
  " An example for a gvimrc file.
  " The commands in this are executed when the GUI is started.
  "
  " To use it, copy it to
  "     for Unix and OS/2:  ~/.gvimrc
  "             for Amiga:  s:.gvimrc
  "  for MS-DOS and Win32:  $VIM\_gvimrc

  " Make external commands work through a pipe instead of a pseudo-tty
  "set noguipty

  " set the X11 font to use
  " set guifont=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1

  " Make command line two lines high
  set ch=2

  " Make shift-insert work like in Xterm
  map <S-Insert> <MiddleMouse>
  map! <S-Insert> <MiddleMouse>

  " Only do this for Vim version 5.0 and later.
  if version >= 500

    " I like highlighting strings inside C comments
    let c_comment_strings=1

    " Switch on syntax highlighting.
    syntax on

    " Switch on search pattern highlighting.
    set hlsearch

    " For Win32 version, have "K" lookup the keyword in a help file
    "if has("win32")
    "  let winhelpfile='windows.hlp'
    "  map K :execute "!start winhlp32 -k <cword> " . winhelpfile <CR>
    "endif

    " Hide the mouse pointer while typing
    set mousehide

    " Set nice colors
    " background for normal text is light grey
    " Text below the last line is darker grey
    " Cursor is green
    " Constants are not underlined but have a slightly lighter background
    highlight Normal guibg=grey90
    highlight Cursor guibg=Green guifg=NONE
    highlight NonText guibg=grey80
    highlight Constant gui=NONE guibg=grey95
    highlight Special gui=NONE guibg=grey95

  endif
  ______________________________________________________________________



  See also sample vimrc used for console mode vim command from
  /usr/doc/vim-common-5.3/vimrc_example.




  22..22..  XXddeeffaauullttss ppaarraammeetteerrss

  You can set some of the Vim properties in Xdefaults file.

   WWAARRNNIINNGG!!!! WWAARRNNIINNGG:: _D_o _N_O_T _p_u_t VViimm**ggeeoommeettrryy it will break the gvim
  menu, use VViimm..ggeeoommeettrryy instead

  Edit the $HOME/.Xdefaults and put the following lines:

  ______________________________________________________________________
  ! GVim great Colors.
  Vim*useSchemes:         all
  Vim*sgiMode:            true
  Vim*useEnhancedFSB:     true
  Vim.foreground:         Black
  !Vim.background:        lightyellow2
  Vim*background:         white
  ! Do NOT use Vim*geometry , this will break the menus instead
  ! use Vim.geometry. Asterik between Vim and geometry is not allowed.
  ! Vim.geometry: widthxheight
  Vim.geometry:           88x40
  !Vim*font:              -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-15-*5
  Vim*menuBackground: yellow
  Vim*menuForeground: black
  ______________________________________________________________________


  In order for this change to take effect, type -

  ______________________________________________________________________
          xrdb -merge $HOME/.Xdefaults
          man xrdb
  ______________________________________________________________________



  You can also edit the ~/.gvimrc file to change the background colors

  ______________________________________________________________________
          gvim $HOME/.gvimrc
  The best background color is lightyellow or white, with black foreground.
          highlight Normal guibg=lightyellow
  ______________________________________________________________________



  33..  CCoolloorr SSyynnttaaxx iinniitt ffiilleess

  Instead of using "Syntax" menu you can also manually source in the
  syntax file. Edit the file with gvim and at : (colon) command give
  'so' command. For example -

  ______________________________________________________________________
          gvim foo.pc
          :so $VIM/syntax/esqlc.vim
  ______________________________________________________________________


  The syntax source files are at /usr/share/vim/syntax/*.vim. Vim sup-
  ports more than 120 different syntax files for different languages
  like C++, PERL, VHDL, Javascript,...and so on!!

  Each syntax file supports a default file extension names, for example,
  Javascript syntax file supports *.js extension. If you happen to use
  different extension conflicting with another default syntax file as in
  putting Javascript in *.html file than you MUST source in with command
  :so $VIM/syntax/javascript.vim. Best method is create a soft link like
  -

  ______________________________________________________________________
          ln -s $VIM/syntax/javascript.vim js
          gvim foo.html  (... this file contains javascript functions and HTML)
          :so js
  ______________________________________________________________________



  44..  VVIIMM UUssaaggee

  You can use Vim in two modes - one with GUI and other without GUI.  To
  use GUI use command -

  ______________________________________________________________________
          gvim foo.cpp
  ______________________________________________________________________


  To use non-gui mode give -

  ______________________________________________________________________
          vim foo.cpp
  OR plain vanilla mode
          vi foo.cpp
  ______________________________________________________________________


  It is very strongly recommended that you always use gvim instead of
  vim, since GUI mode with colors will definitely improve your produc-
  tivity.

  GUI mode gvim provides the following -

  +o  You can mark the text using the mouse to do cut, copy and paste.

  +o  You can use the Menu bar which has - File, Edit, Window, Tools,
     Synatx and Help buttons.

  +o  Also in near future in gvim - a second menu bar will display the
     list of files being edited, and you can switch files by clicking on
     the filenames, untill than you can use vi commands - :e#, :e#1,
     :e#2, :e#3, :e#4, ....so on to select the files.

  55..  VVii ccoommppaanniioonnss

  Generally Vim is used in conjunction with other powerful tools like
  ccttaaggss and ggddbb. The ccttaaggss is for very rapid navigation through millions
  of lines of "C/C++" code and ggddbb for debugging the "C/C++" code.  A
  brief introduction of these two indispensable commands will be given
  in this chapter.

  The ccttaaggss is the most powerful command available for coding C, C++,
  Java, Perl, Korn/Bourne shell scripts or Fortran. Developers very
  extensively use ccttaaggss to navigate "to and fro" thousands of functions
  of C/C++ programs. See 'man ctags' on Unix.  It is vveerryy iimmppoorrttaanntt that
  you MUST learn how to use ctags in order to develop programs in C or
  C++, Java, etc.. Navigation is the single most important task while
  doing development of C or C++ code. Using ctags you can very quickly
  read the code by jumping from calling line to function and drill down
  deeper into nested function calls and unwind back all the way upto the
  top. You can go back and forth from function to function very quickly.


  Without NAVIGATION you will be completely lost! ccttaaggss is like the
  magnetic COMPASS needle for the programmers.

  Usage of ccttaaggss :

  ______________________________________________________________________
          ctags *.cpp
          gvim -t foo_function
          gvim -t main
  ______________________________________________________________________


  This will edit the C++ program file which contains the function
  foo_function() and will automatically place the cursor on the first
  line of the function foo_function(). The second command takes you to
  line having main() function definition.

  Inside the Vim editor, you can jump to a function by typing : (colon)
  tag < function name >as below -

  ______________________________________________________________________
          :tag sample_function
  ______________________________________________________________________


  This will place the cursor on first line of sample_function()

  If you want to jump into the function from a line in file which
  contains the function name, place the cursor just before the function
  name and press CCTTRRLL++]] (press control key and left-square-bracket key
  simultaneously), this will take you right at the line where the
  function begins automatically!!

  ______________________________________________________________________
                  // example code
                  switch(id_number) {
                          Case 1:
                                  if ( foo_function( 22, "abcef") == 3 )
                                      ^
                                      |
                                      |
                                      |
                    Place the cursor here (just before foo_function) and press CTRL+]
                    This will take you to function by name "foo_function". To come back to this line press CTRL+t
  ______________________________________________________________________


  To go back to the calling line press CCTTRRLL++tt (Control key and letter
  't' together). You keep pressing CCTTRRLL++tt to unwind and go to the first
  line where you started the navigation. That is you can keep pressing
  CCTTRRLL++]] and than keep pressing CCTTRRLL++tt to go back. You can repeat these
  as many times you want to have complete navigation through all the
  functions of C or C++.

  55..11..  CCttaaggss ffoorr EESSQQLL

  Since ctags directly does not support the Embedded SQL/C (ESQL)
  language, the following shell script can be used to create tags for
  esql. ESQL/C is database SQL commands embedded inside the "C"
  programs.  Oracle's ESQL/C is called Pro*C and Sybase, Informix have
  ESQL/C and PostgreSQL has product "ecpg".

  Save this file as "sqltags.sh" and do chmod a+rx tags_gen.sh.



  ______________________________________________________________________
  #!/bin/sh

  # Program to create ctags for ESQL, C++ and C files
  ESQL_EXTN=pc
  tag_file1=tags_file.1
  tag_file2=tags_file.2

  which_tag=ctags

  rm -f $tag_file1 $tag_file2 tags

  aa=`ls *.$ESQL_EXTN`
  #echo $aa
  for ii in $aa
  do
          #echo $ii
          jj=`echo $ii | cut -d'.' -f1`
          #echo $jj

          if [ ! -f $jj.cpp ]; then
                  echo " "
                  echo " "
                  echo "***********************************************"
                  echo "ESQL *.cpp files does not exist.. "
                  echo "You must generate the *.cpp from *.pc file"
                  echo "using the Oracle Pro*C pre-compiler or Sybase"
                  echo "or Informix esql/c pre-compiler."
                  echo "And than re-run this command"
                  echo "***********************************************"
                  echo " "
                  exit
          fi

          rm -f tags
          $which_tag $jj.cpp
          kk=s/$jj\.cpp/$jj\.pc/g

          #echo $kk > sed.tmp
          #sed -f sed.tmp tags >> $tag_file1

          #sed -e's/sample\.cpp/sample\.pc/g' tags >> $tag_file1
          sed -e $kk tags >> $tag_file1
  done

  # Now handle all the C++/C files - exclude the ESQL *.cpp files
  rm -f tags $tag_file2
  bb=`ls *.cpp *.c`
  aa=`ls *.$ESQL_EXTN`
  for mm in $bb
  do
          ee=`echo $mm | cut -d'.' -f1`
          file_type="NOT_ESQL"
          # Exclude the ESQL *.cpp and *.c files
          for nn in $aa
          do
                  dd=`echo $nn | cut -d'.' -f1`
                  if [ "$dd" = "$ee" ]; then
                          file_type="ESQL"
                          break
                  fi
          done

          if [ "$file_type" = "ESQL" ]; then
                  continue
          fi
          rm -f tags
          $which_tag $mm
          cat tags >> $tag_file2
  done

  mv -f $tag_file2 tags
  cat  $tag_file1 >> tags
  rm -f $tag_file1

  # Must sort tags file for it work properly ....
  sort tags > $tag_file1
  mv $tag_file1 tags
  ______________________________________________________________________



  55..22..  CCttaaggss ffoorr JJaavvaassccrriipptt pprrooggrraammss,, KKoorrnn,, BBoouurrnnee sshheellllss

  The shell script given below can be used to generate tags for a very
  large variety of programs written in JavasScript, PHP/FI scripts, Korn
  shell, C shell, Bourne shell and many others. This is a very generic
  module.

  Save this file as tags_gen.sh and do chmod a+rx tags_gen.sh.










































  ______________________________________________________________________
  #!/bin/sh

  tmp_tag=tags_file
  tmp_tag2=tags_file2

  echo " "
  echo " "
  echo " "
  echo " "
  echo " "
  echo "Generate tags for ...."
  while :
  do
          echo "    Enter file extension for which you want to generate tags."
          echo -n "    File-extension should be like sh, js, ksh, etc... : "
          read ans

          if [ "$ans" == "" ]; then
                  echo " "
                  echo "Wrong entry. Try again!"
          else
                  break
          fi
  done

  \rm -f $tmp_tag

  aa=`ls *.$ans`

  for ii in $aa
  do
          jj=`echo $ii | cut -d'.' -f1`
          #echo $jj
          cp $ii $jj.c
          ctags $jj.c
          echo "s/$jj.c/$ii/g" > $tmp_tag2
          sed -f $tmp_tag2 tags >> $tmp_tag
          \rm -f tags $jj.c
  done

  sort $tmp_tag > tags

  \rm -f $tmp_tag $tmp_tag2
  ______________________________________________________________________



  55..33..  DDeebbuuggggeerr ggddbb

  You would be using gdb extensively along with Vi.  Debugging is the
  most important aspect of programming as major cost of software project
  goes into debugging and testing.

  To debug C++/C programs use 'gdb' tool. See ''mmaann ggddbb''.  You must
  compile your programs with -g3 option like


               gcc -g3 foo.c foo_another.c sample.c




  To setup easy aliases do -


    Setup a alias in your ~/.bash_profile
          alias gdb='gdb -directory=/home/src -directory=/usr/myname/src '
    Give -
          gdb foo.cpp
          gdb> dir /hom2/another_src
          This will add to file search path
          gdb> break 'some_class::func<TAB><TAB>
    This will complete the function name saving you typing time... and will output like -
          gdb> break 'some_class::function_foo_some_where(int aa, float bb)'




  Pressing TAB key twice is the command line completion, which will save
  you lots of typing time. This is one of the most important technique
  of using gdb.

  To get online help do -


               gdb> help
         Gives online help
               gdb> help breakpoints
         Gives more details about breakpoints.




  To set breakpoints and do debugging


               unixprompt> gdb exe_filename
               gdb> b main
         This will put breakpoint in main() function
               gdb> b 123
         This will put breakpoint in line 123 of the current file
               gdb> help breakpoints
         Gives more details about breakpoints.




  To analyze the core dumps do


               unixprompt> gdb exe_filename  core
               gdb> bt
         Gives backtrace of functions and line numbers where the program failed
               gdb> help backtrace
         Gives more details about backtrace.




  You can also use GUI version of gdb called xxgdb.

  Memory leak tools -

  +o  Freeware Electric Fence on linux cd,

  +o  Commercial tools Purify  <http://www.rational.com>

  +o  Insure++  <http://www.insure.com>



  66..  OOnnlliinnee VVIIMM hheellpp

  See the online man pages. At unix shell prompt type ''mmaann vviimm'' and ''mmaann
  ggvviimm''.

  Or inside the gvim session type :help to get the help page. See also
  ``''



                               VIM - main help file

             Move around:  Use the cursor keys, or "h" to go left,
                           "j" to go down, "k" to go up, "l" to go right.
                           ":1" takes you to 1st line of page
                           ":n" takes you to nth line of page
                           "<SHIFT>g" takes you to bottom of page
                           ":/someword/ will search for "someword" in doc

       Close this window:  Use ":q<Enter>".

       Jump to a subject:  Position the cursor on a tag between |bars| and hit CTRL-].

          With the mouse:  ":set mouse=a" to enable the mouse (in xterm or GUI).
                           Double-click the left mouse button on a tag between |bars|.

               jump back:  Type CTRL-T or CTRL-O.

       Get specific help:  It is possible to go directly to whatever you want help
                           on, by giving an argument to the ":help" command |:help|.
                           It is possible to further specify the context:
                                 WHAT                  PREPEND    EXAMPLE      ~
                             Normal mode commands     (nothing)   :help x
                             Visual mode commands        v_       :help v_u
                             Insert mode commands        i_       :help i_<Esc>
                             command-line commands       :        :help :quit
                             command-line editing        c_       :help c_<Del>
                             Vim command arguments       -        :help -r
                             options                     '        :help 'textwidth'

       list of documentation files:

       |howto.txt|     how to do the most common things
       |intro.txt|     introduction to Vim
       |index.txt|     alphabetical index for each mode
       |autocmd.txt|   automatically executing commands on an event
       |change.txt|    delete and replace text




  77..  VViimm HHoommee ppaaggee aanndd VViimm lliinnkkss

  The home page of vim is at  <http://www.vim.org> and mirror site in US
  is at  <http://www.us.vim.org>

  Vim FAQ is at  <http://www.grafnetix.com/~laurent/vim/faq.html> and at
  <http://www.vim.org/faq>

  Eli's Vim Page at  <http://www.netusa.net/~eli/src/vim.html>

  The Vi Lovers Home Page  <http://www.cs.vu.nl/~tmgil/vi.html>

  Vim Reference Guide at  <http://scisun.sci.ccny.cuny.edu/~olrcc/vim/>


  Vim mailing list at
  <http://www.findmail.com/listsaver/vimannounce.html> and
  <http://www.vim.org/mail.html>

  Mailing list archives are kept at:

  +o  <http://www.egroups.com/group/vim>

  +o  <http://www.egroups.com/group/vimdev>

  +o  <http://www.egroups.com/group/vimannounce>

  Vim macros  <http://www.grafnetix.com/~laurent/vim/macros.html>

  88..  VViimm TTuuttoorriiaall


  88..11..  VViimm HHaannddss--oonn TTuuttoorriiaall

  On Linux system see the tutorial at /usr/doc/vim-common-5.*/tutor, on
  other unix systems go to directory where vim is installed and look for
  doc directory.

  ______________________________________________________________________
          cd /usr/doc/vim-common*/tutor
          less README.txt
          cp tutor $HOME
          cd $HOME
          less tutor
  ______________________________________________________________________



  88..22..  VVii TTuuttoorriiaallss oonn IInntteerrnneett


  +o  Purdue University
     <http://ecn.www.ecn.purdue.edu/ECN/Documents/VI/>



  +o  Quick Vi tutorial  <http://linuxwww.db.erau.edu/LUG/node165.html>



  +o  Advanced Vi tutorial  <http://www.yggdrasil.com/bible/bible-
     src/user-alpha-4/guide/node171.html>



  +o  Tutorials  <http://www.cfm.brown.edu/Unixhelp/vi_.html>



  +o  Tutorials
     <http://www.linuxbox.com/~taylor/4ltrwrd/section3_4.html>



  +o  Unix world online vi tutorial
     <http://www.networkcomputing.com/unixworld/unixhome.html>



  +o  Univ of Hawaii tutorial  <http://www.eng.hawaii.edu/Tutor/vi.html>

  +o  InfoBound   <http://www.infobound.com/vi.html>



  +o  Cornell Univ  <http://www.tc.cornell.edu/Edu/Tutor/Basics/vi/>



  +o  Vi Lovers home page:  <http://www.cs.vu.nl/~tmgil/vi.html>

  +o  Ater Sept 2000, will moveto
     <http://www.thomer.com/thomer/vi/vi.html>



  +o  Beginner's Guide to vi
     <http://www.cs.umr.edu/unixinfo/general/packages/viguide.html>



  +o  vi Help file  <http://www.vmunix.com/~gabor/vi.html>



  +o  vim FAQ  <http://www.math.fu-berlin.de/~guckes/vim/faq/>

     There are many Vi Tutorials on internet. In Yahoo (Lycos, excite or
     Hotbot) enter "Vi Tutorial" in search field and search engine will
     return many pointers.

  99..  VVii TTuuttoorriiaall

  In this tutorial, we describe some "advanced" vvii concepts and
  commands, so you can appreciate the power of vvii and so you decide how
  to build your knowledge of vvii commands. Nearly all vvii references list
  the available commands, but many don't bother to discuss how the
  commands interrelate; this topic is the main purpose of this tutorial.

  99..11..  CCuurrssoorr MMoovveemmeenntt CCoommmmaannddss

  The vvii cursor movement commands allow you to position the cursor in
  the file and/or on the screen efficiently, with a minimum number of
  keystrokes. There are oodles of cursor movement commands - don't try
  memorizing them all at once! Later, we'll see that much of the power
  of vvii comes from mixing cursor movement commands with other commands
  to delete, change, yank (copy), and filter text.

  Please edit a large text file (say, wwkknniigghhtt) so you can experiment
  with each command as it is described. Keep in mind these commands will
  only work in Command Mode, not Insert Mode; if you start getting your
  "commands" in your text, press the ESC key to return to Command Mode.


  +o  ccuurrssoorr kkeeyyss : As we've seen, cursor keys move by single character
     amounts left, down, up, and right. Movement above the top of the
     file, below the bottom, to the right of the end of a line, or left
     of the beginning is not allowed (no line wrapping).



  +o  hhjjkkll : When vvii was written (around 1978), many terminals on UNIX
     systems did not have cursor keys! hh,, jj,, kk,, and ll were chosen as
     commands to move left, down, up, and right, respectively.  Try
     them! Most vvii diehards prefer these to the cursor keys because


  +o  ((aa)) they are in the same place on all keyborads, and

  +o  ((bb)) they fit nicely under the fingers, unlike most cursor keys,
     which are arranged in a box or "T" or some other nonlinear shape.


     Why h, j, k, and l? Well, in the ASCII character set, CTRL-H is
     backspace (moves left), CTRL-J is linefeed (moves down), and, of
     course, k and l are next to h and j, so you see, they're mnemonic.



  +o  00 : ("zero", not "oh") Move to the beginning of current line. (To
     try this and the next few commands, use the cursor keys or hh jj kk ll
     to move to an indented text line that contains few "e" characters.
     If you can't find an indented line in your file, create one by
     inserting a few space characters at the beginning of a line.)



  +o   ^^  : Move to first non-white character of current line. (For
     indented line, 0 and ^ are different.)



  +o   $$  : Move to last character of current line.



  +o   ttCC  : Move to (but not on) next character c in current line.
     (Press 0, then press te. This will move to the first e in the
     curent line.)



  +o   ffCC  : Find (move on top of) next character c in current line.
     (Press fe, and the cursor will find - that is, move on top - the
     next e in the current line.)



  +o   TTCC  : Move to (but not on) the previous character c in current
     line (Press $, than Te.)



  +o   FFCC  : Find (move on top of) the previous character c in current
     line.  (Press Fe.)



  +o   nn||  : Move to column n in current line. (Try 20 |. The digits 2
     and 0 will not be displayed as you type them, but when you press |
     the cursor will move to column 20.)

     Try some experiments with t f T F | . When you do something
     illegal, vvii will beep your terminal.



  +o   ww  : Forward to beginning of next "small" word ( a "small" word
     consists of unbroken alphanumeric characters or punctuation
     characters, but not mixed alphanumeric and punctuation). Try
     tapping w a dozen times or so - note what happens at punctuation.


  +o   WW  : Forward to beginning of next "big" word (alphanumeric and
     punctuation mixed). Try W a dozen times or so.



  +o   bb  : Backward to beginning of "small" word.



  +o   BB  : Backward to beginning of "big" word.



  +o   ee  : Forward to end of "small" word.


  +o   EE  : Forward to end of "big" word.



  +o   ++ RReettuurrnn  : Move to first non-white space character on next line.
     (+ and the Return key have the same effect.)



  +o   --  : Move to first non-white space character on previous line.



  +o   ))  : Move to the end of sentence. (A sentence ends either at a
     blank line or at a period or examination mark followed by two space
     characters or at the end of a line. A period or exclamation mark
     followed by one space character does not end a sentence; this is
     correct behaviour, according to traditional rules of how sentences
     should appear in typed documents, but often appears wrong to those
     who have never suffered through a fromal typing class.)



  +o   ((  : Move to beginning of sentence.



  +o   }}  : Move to end of paragraph. (Paragraphs are seperated with
     blank lines, by vvii's definition.)



  +o   {{  : Move to beginning of paragraph.



  +o   HH  : Move to home position (top line) on the screen



  +o   MM  : Move to middle line on the screen.



  +o   LL  : Move to last line on the screen.



  +o   nnGG  : Move to line n. If n is not given, move to the last line in
     the file.  (Try 15G to move to line 15, for example. The CTRL-G
     command displays the name of the file, some status information, and
     the current line number. To move to the top of the file: 1G)



  +o   CCTTRRLL--dd  : Scroll down half-screen (see note).

  +o   CCTTRRLL--uu  : Scroll up half-screen (see note).

  +o   CCTTRRLL--ff  : Move forward one-screen (see note).

  +o   CCTTRRLL--bb  : Move backward one-screen (see note).

  +o   NNoottee  : These four scrolling/paging commands cannot be used with
     the delete, change, yank, or filter commands.



  +o   //rreegg__eexxpp  : Move to next occurrence of the regular expression
     reg_exp When you press /, the cursor drop to the lower left corner
     of the screen and waits for you to type in the regular expression.
     Press the Return key to finish; vvii then searches forward for the
     next occurrence of the regular expression. For example, press /the
     followed by Return. This moves forward to the next occurrence of
     the, perhaps imbedded in the middle of some longer word (other,
     weather, etc.). If you just press / and then Return, vvii searches
     for the next occurrence of whatever the last regular expression was
     that you searched for.



  +o   nn  : Has the same effect as pressing / and then Return; i.e.,
     searches for the next occurrence of whatever the last regular
     expression was that you searched for.



  +o   ??rreegg__eexxpp  : Searches backward, rather than forward. If no reg_exp
     is given, it searches for the last regular expression that was
     entered.  Both / and ? wrap around, so searching "below" the bottom
     or "above" the top of the file is legal.



  +o   NN  : Same as pressing ? and then Return.

  99..22..  RReeppeeaatt CCoouunnttss

  Many of the movement commands discussed above can be preceded with a
  repeat count; the movement is simply repeated the given number of
  times:

  +o   33ww  : Move forward three words

  +o   55kk  : Move up four characters

  +o   33ffaa  : Find the third succeeding a in current line

  +o   66++  : Move down six lines

     For some commands, the "repeat counts" has special meaning:

  +o   44HH  : Move to Line 4 on the screen (home plus 3)

  +o   88LL  : Move to the eigth line from the bottom of the screen

  +o   33$$  : Move to the end of the third line down

     For some commands (e.g., ^) the repeat count is ignored; for others
     (e.g., / and ? ) it is illegal

  99..33..  DDeelleettiinngg TTeexxtt

  We've seen that dddd deletes the current line. This can be used with a
  repeat count: 3dd deletes three lines, the current line, and the two
  following lines.

  The d command can be used as a "prefix" on most of the movement
  commands above to delete nearly arbitrary chunks of text. When used
  with d, the movement commands are called target specifiers. d can be
  given a repeat count. (As you try these experiments, remember to press
  u after each command to undo the deletion).


  +o   ddww  : Delete "small" word forward

  +o   dd33ww  : Delete three "small" words forward

  +o   33ddww  : Three times, delete "small" word forward

  +o   33dd33ww  : Three times, delete three "small" words forward (that is,
     delete nine "small" words forward)

  +o   dd++  : Delete current line and next line down

  +o   dd//tthhee : Delete from current character up to but not including the
     next occurrence of the pattern the.

  +o   dd$$  : Delete to end of line

  +o   dd00  : Delete to beginning of line

  +o   dd3300GG  : Delete from the curent line to and including Line 30

  +o   ddGG  : Delete from current line to and including last line

  +o   dd11GG  : Delete from current line to and including Line 1

     To delete single characters, use x. x can be given a repeat count:

  +o   1155xx  : Delete current and 14 following characters

     x is actually just an abbreviation of d1; that is, delete one
     character right.

  99..44..  CChhaannggiinngg TTeexxtt

  The c command is similar to d, except it toggles vvii into Insert Mode,
  allowing the original (unwanted) text to be changed to something else.

  For example, put the cursor on the beginning of a word (press w to get
  to the beginning of the next word). Then, press cw to change that
  word. On the screen, the last character in the word being changed will
  be replaced with a $$ symbol indicating the boundary of the change;
  type ina new word (you will overwrite the original word on the screen)
  and press the ESC key when done.  Your input may be longer or shorter
  than the word being changed.

  Put the cursor at the beginning of a line containing at least three
  words, and try c3w to chage three words. Try c$ to change to the end
  of the current line.  In all cases where the chage affects only the
  current line, the boundary of the change is indicated with $.
  When a change affects more than just the current line, vvii deletes the
  original text from the screen and toggles into Insert Mode. For
  example, try c3+ to change the current and the next three lines; vvii
  deletes the four original lines from the screen and toggles into
  Insert Mode in a new blank line.  As usual, press the ESC key when you
  have finished entering your new text.

  Some other change commands:

  +o   cccc  : Change current line

  +o   55cccc  : Change five lines (current and next four)

  +o   cc//tthhee  : Change from current character up to but not including the
     next occurrence of the pattern the

  +o   cc$$  : Change to end of line

  +o   cc3300GG  : Change from the current line to and including Line 30

  +o   ccGG  : Change from curernt line to and including last line

  +o   cc11GG  : Change from curernt line to and including Line 1

  99..55..  YYaannkkiinngg ((CCooppyyiinngg)) TTeexxtt

  The y command yanks a copy of  text into a buffer; the yanked text can
  then be put (or pasted) elsewhere in the file using p or P.

  The simplest form of yank is yy to yank the current line; after yy,
  try p to put a copy of the yanked line after the cursor. Following yy,
  you can make as many copies of the yanked line as you want by moving
  up and down in the file and pressing p.

  To copy multiple lines, try, for example, 5yy (yank the current and
  next four lines). p puts a copy of the yanked lines after the cursor;
  the sequence 5yyp "works" but it probably doesn't do what you would
  like. The P command is like p, but puts a copy of the yanked text
  ahead of the cursor; try the sequence 5yyP.

  Other yank commands:

  +o   yy33ww  : Yank three words

  +o   yy$$  :  Yank to end of current line

  +o   yy11GG  : Yank from current line to and including Line 1

  99..66..  FFiilltteerriinngg tteexxtt

  The filter command !!, prompts for the name of a UNIX command (which
  should be a filter), then passes selected lines through the filter,
  replacing those selected line in the vvii buffer with the output of the
  filter command. vvii's ability to pass nearly arbitrary chunks of text
  through any UNIX filter adds incredible flexibility to vvii, at no
  "additional cost" in size or performance to vvii itself.

  Some examples will help illustrate. Create a line in your file
  containing just the word who and absolutely no other text. Put the
  cursor on this line, and press !!!!  This command is analogous to dd,
  cc, or yy, but instead of deleting, changing, or yanking the current
  line, it filters the current line. When you press the second !, the
  cursor drops down to the lower left corner of the screen and a single
  ! is displayed, prompting you to enter the name of a filter. As the
  filter name, type sh and press the Return key. sshh (the Bourne shell)
  is a filter!  It reads standard input, does some processing of its
  input (that is, executes commands), and sends its output (the output
  of those commands) to standard output. Filtering theline containing
  who through sh causes the line containing who to be replaced with a
  list of the current users on the system - right in your file!

  Try repeating this process with ddaattee. That is, create a line
  containing nothing but the word ddaattee, then put the cursor on the line,
  and press !!!!sshh and the Return key. The line containing ddaattee is
  replaced with the output of the ddaattee command.

  Put your cursor on the first line of the output of who. Count the
  numebr of lines.  Suppose, for example, the number is six. Then select
  those six lines to be filtered through sort; press 66!!!!ssoorrtt and the
  Return key. The six lines will be passed through sort, and sort's
  output replaces the original six lines.

  The filter command can only be used on complete lines, not on
  characters or words.

  Some other filter commands (here, < CR > means press Return):

  +o  !!//tthhee << CCRR >> ssoorrtt << CCRR >> : Sort from the current line up to and
     including the next line containing the

  +o   !!11GGggrreepp tthhee << CCRR >> : Replace from the current line to and
     including Line 1 with just the lines that contain the

  +o   !!GGaawwkk ''{{pprriinntt $$11}}'' << CCRR >> : From the current line to the end of
     file, replace every line with just its first word.

  99..77..  MMaarrkkiinngg LLiinneess aanndd CChhaarraacctteerrss

  You can mark lines and characters to be used as targest for movement,
  deletion, change, yankidn, and filtering using the command mc, where c
  is a lowercase letter.

  For example, put the cursor in the middle of some word and press ma.
  This marks the character under the cursor as mark a.

  Now, move the cursor off the marked character and to a different line
  ( use the cursor keys, CTRL-u, or whatever). To return to the marked
  line, press 'a (that is, single quote, than a). This moves to the
  first non-white space character on the line containing mark a.

  Move off that line again. To return to the marked character, press `a
  (that is, backquote, than a). This moves on top of the character
  marked with a.

  Marking is usually used with deleting, changing, yanking or filtering.
  For example, move the cursor to al line other than the one containing
  mark a, and then press d'a (d, single quote, a). This deletes from the
  current line to and including the line marked with a.

  Put the cursor in the middle of a different word and press mb to set
  mark b.  Now, move the cursor away from that word (but only a few
  lines, so you can see what we're about to do more easily), and than
  press d`b (d, backquote, b).  This deletes from the current CHARACTER
  to and including the CHARACTER marked with b.

  As another example, to sort the output of who, mark the first line
  (ma), then move the cursor to the last line and press !'asort and the
  Return key.

  If you jump to a mark and decide you want to jump back to whatever you
  jumped from, you can press '' (jump back to line) or `` (jump back to
  character).
  99..88..  NNaammiinngg BBuuffffeerrss

  When you delete, change, or yank text, the original text is stored
  (until the next delete, change, or yank) in an unnamed buffer from
  which it can be put using p or P. Using the unnamed buffer, only the
  most recently deleted, changed or yanked text may be recovered.

  If you wish to delete, change, or yank multiple sections of text and
  remember them all (up to a maximum of 26), you can give a buffer name
  ahead of the delete change or yank command. A buffer name has the form
  "c (double quote, lowercase c).

  For example, press "ayy to yank the current line into buffer a, then
  move to a different line and press "byy to yank that line into buffer
  b. Now, move elsewhere in the file and press "ap and "bp to put copies
  of the text stored in buffers a and b.

  Some other named buffer commands:

  +o   ""aa66yyyy  : Yank six lines (current and next five) into buffer a

  +o   ""bbdd11GG  : Delete from the curernt line to and including Line 1,
     storing the deleted lines in buffer b

  +o   ""ccyy''cc  : Yank from the current line to the line marked c into
     buffer c (marks and buffers are distinct, and may have the same
     name without confusing vvii)

  99..99..  SSuubbssttiittuuttiioonnss

  To substitute one chunk of text for another in lines throughout your
  file, use the :s command. Some subsitute examples:

  +o   ::11,,$$ss//tthhee//TTHHEE//gg   From Line 1 to the last line (line $), subsitute
     for the text THE; do this globally in each line where the occurrs

  +o   ::''aa,,..ss//..**//hhaa hhaa//  From the line marked a to the current line (line
     .), substitute for everything on the line the text ha ha

  99..1100..  MMiisscceellllaanneeoouuss ""CCoolloonn CCoommmmaannddss""

  All colon commands begin with a colon; when you press the colon, the
  cursor drops to the lower left corner of the screen, and a colon
  prompt is displayed waiting for you to finish your colon command.

  Some important examples:

  +o  ::ww  Write the buffer contents to the file without quitting from vvii

  +o  ::ww aabbcc Write the buffer contents to the file abc (creating abc if
     it doesn't exist, or overwriting current contents if it does exist)
     without quitting from vvii

  +o  ::11,,1100ww  aabbcc  Write lines 1 through 10 to file abc

  +o  ::''aa,,$$ww aabbcc  Write from the line marked a to the last line into file
     abc

  +o  ::ee aabbcc Edit file abc, instead of the current file. vvii prints an
     error message if changes have been made to the curernt file that
     have not been saved with :w

  +o  ::ee!! aabbcc Edit file abc, throwing away any changes that may have been
     made to the current file


  +o  ::ee ##  Edit the prior file edited (successive :e# commands toggle
     back and forth between two files)

  +o  ::ff aabbcc  Change the file anme for the current vvii buffer to abc

  +o  ::qq Quit, unless unsaved chanegs have been made

  +o  ::qq!! Quit, throwing away any changes that may have been made

  +o  ::rr aabbcc Read the file abc into current vvii buffer, after the line the
     cursor is on (try :r croc to read in a copy of the croc file)

  +o  ::!!ccmmdd Execute command cmd (who, sort, ls, etc.)

  99..1111..  SSeettttiinngg OOppttiioonnss

  Various options affect the "feel" of vvii. You can display all the
  various options that can be set using the colon command :set all. You
  can also use set to change options.

  For example, if you want to see line numbers for the lines in the file
  you're editing, use the command :set number. To turn off line
  numbering, use the command :set nonumber. Most options can be
  abbreviated; :set nu turns on line numbering and :set nonu turns off
  line numbering.

  If you :set nomagic, the special meanings of regular expression
  characters (period, asterisk, square bracket, etc.) are switched off.
  Use :set magic to restore the special meanings.

  Some options take a value. For example, :set tabstop=4 causes tabs to
  be displayed as four space characters, rather than the usual eight.

  If you find you always want certain options set certain ways, you can
  put the set commands you want ina file .exrc, or you can set up the
  environment variable EXINIT to specify the options you want.

  For example, if your lgoin shell is Bourne shell, this line could go
  in your .profile file:

  ______________________________________________________________________
          EXINIT='set nomagic nu tabstop=4'; export EXINIT
  ______________________________________________________________________


  If your login shell is a C shell, this line could go in your .login
  file:

  ______________________________________________________________________
          setenv EXINIT 'set nomagic nu tabstop=4'
  ______________________________________________________________________



  99..1122..  KKeeyy MMaappppiinnggss

  If you find you're performing a series of simple commands over and
  over, you can map the command series to an unused command key using
  the :map command. If your mapping must include control characters such
  as Return key (CTRL-M in ASCII) or the ESC (CTRL-[ in ASCII) key,
  precede such characters with CTRL-v to suppress their usual special
  meaning.

  For example, this command maps CTRL-A to move the cursor forward 55
  lines, then back up to the msot recent blank line, then change that
  blank line to a formfeed (CTRL-L) and three blank lines. That is, each
  CTRL-A will paginate the next page, without splitting paragraphs
  across pages.

  Note: In this command, each control character is shown as ^C, where C
  is some uppercase letter. For example, CTRL-M is shown as ^M. Also,
  when you enter this command you will not see the CTRL-v characters as
  shown: each CTRL-v merely suppresses the usual special meaning of the
  following control character, so when you press the sequence ^V^M, all
  you will see on the screen is ^M. In this command, ^M is the Return
  key and ^[ is the ESC key.

  ______________________________________________________________________
          :map ^A  55+?^$^V^Mcc^V^L^V^M^V^M^V^M^V^[
  ______________________________________________________________________



  99..1133..  EEddiittiinngg MMuullttiippllee FFiilleess

  You can edit multiple files with vvii by giving multiple file names as
  command line arguments:

  ______________________________________________________________________
          vi croc fatherw  wknight
  ______________________________________________________________________


  Two colon commands are used to move through the multiple files:

  +o   ::nn  Move to the next file in the argument list (you must save
     changes with :w or vvii will print an error message)

  +o   ::rreeww Rewind and start over with the first file in the argument
     list

     The :n and :rew commands aer somewhat clumsy, but there are some
     important benefits: the contents of named buffers ("a, "b, "c,
     etc.) are remembered across files, so you can use :n and :rew with
     p and P to copy text back and forth between files. Also, the most
     recent search string for the / and ? commands remembered across
     files, so you can do repetitive searches in multiple files rather
     easily.

  For example, try the following experiment: First get out of vvii, then
  execute vvii with croc and wknight as arguments:

  ______________________________________________________________________
          $ vi croc wknight
  ______________________________________________________________________


  In croc, search for the

       //tthhee << CCRR >>

  Yank this line into buffer a:

       ""aayyyy

  Now go to the next file (you've made no change to croc, so this will
  work):

       ::nn << CCRR >>

  Search for the "next" line containing the, without retyping the search
  string:
       nn

  Put a copy of buffer a after the current line in wknight:

       ""aapp

  Move down two lines, and yank the current line into buffer b:

       jjjj""bbyyyy

  Save the changes to wknight

       ::ww << CCRR >>

  Now, rewind to croc

       ::rreeww << CCRR >>

  Search again, and put a copy of buffer b after the found line:

       nn""bbpp

  Save the changes, and exit vvii

       ZZZZ

  99..1144..  FFiinnaall RReemmaarrkkss

  This tutorial was intended to introduce some of the vvii capabilities
  that you might overlook in your system's vvii manual or that might not
  be mentioned in the manual (different systems have manuals of widely
  varying quality).

  You will not be a vvii expert after reading this tutorial, but you will
  have a good appreciation of vvii's capabilities. Only time and effort
  can make a vvii expert. But the efficiency and universality of vvii make
  this effort pay off in the long run.

  You may have decided you hate vvii. So be it! But be aware that vvii
  remains the standard UNIX text editor - the one editor you can count
  on being available on every UNIX system you'll use - so even if you
  prefer to use something else day-to-day, you'd be well advised to know
  the bare minimum vvii material covered in this tutorial.

  1100..  VViimm RReeffeerreennccee CCaarrdd


  1100..11..  VVii ssttaatteess

  Vi has 3 modes:

  1. _c_o_m_m_a_n_d _m_o_d_e - Normal and initial state; others return here (use
     EESSCC to abort a partially typed command)

  2. _i_n_p_u_t _m_o_d_e - entered by specific commands aa ii AA II oo OO cc CC ss SS RR
     and ended by EESSCC or abnormally with interrupt

  3. _l_i_n_e _m_o_d_e - i.e. waiting for input after a :: , // , ??  or a !!
     command (end with CCRR, abort with CCTTRRLL--cc). CCTTRRLL is the control key:
     CCTTRRLL--cc means "control c"

  1100..22..  SShheellll CCoommmmaannddss


  1. TTEERRMM== _c_o_d_e Puts a code name for your terminal into the variable
     TTEERRMM
  2. eexxppoorrtt TTEERRMM Conveys the value of TTEERRMM (the terminal code) to any
     UNIX system program that is terminal dependant.

  3. ttppuutt iinniitt Initializes the terminal so that it will function
     properly with various UNIX system programs.

  4. vvii  _f_i_l_e_n_a_m_e Accesses the vvii screen editor so that you can edit a
     specified file.

  5. vvii  _f_i_l_e_1 _f_i_l_e_2 _f_i_l_e_3 Enters three files into the vvii buffer to be
     edited. Those files are _f_i_l_e_1_, _f_i_l_e_2_, and _f_i_l_e_3.

  6. vviieeww  _f_i_l_e Invoke vi editor on _f_i_l_e in read-only mode

  7. vvii --RR  _f_i_l_e Invoke vi editor on _f_i_l_e in read-only mode

  8. vvii --rr  _f_i_l_e Recover _f_i_l_e and recent edits after system crash

  9. vvii --rr  _f_i_l_e Recover _f_i_l_e and recent edits after system crash

  1100..33..  SSeettttiinngg OOppttiioonnss


  1. ::sseett _o_p_t_i_o_n Activate _o_p_t_i_o_n

  2. ::sseett _o_p_t_i_o_n_=_v_a_l_u_e Assign _v_a_l_u_e to _o_p_t_i_o_n

  3. ::sseett nnoo _o_p_t_i_o_n Deactivate _o_p_t_i_o_n

  4. ::sseett  Display options set by user

  5. ::sseett aallll Display list of all current options, both default and
     those set by the user

  6. ::sseett  _o_p_t_i_o_n? Display values of _o_p_t_i_o_n

  1100..44..  NNoottaattiioonnss uusseedd

  Notations:

  1. CCTTRRLL--cc CCTTRRLL is the control key: CCTTRRLL--cc means "control c"

  2. CCRR is Carriage return (ENTER key)

  1100..55..  IInntteerrrruuppttiinngg,, ccaanncceelllliinngg


  +o  EESSCC end insert or incomplete command

  +o  CCTTRRLL--?? CCTTRRLL is the control key: CCTTRRLL--?? means "control ?" delete or
     rubout interrupts

  +o  CCTTRRLL--ll reprint/refresh screen if CTRL-? scrambles it

  1100..66..  FFiillee MMaanniippuullaattiioonn


  +o  ZZZZ Save the file and exit vi

  +o  ::wwqq Save the file and exit vi

  +o  ::ww Write the current file

  +o  ::ww!! Force write the current file, if file is read-only


  +o  ::ww_n_a_m_e Write to file _n_a_m_e

  +o  ::qq Exit from vi

  +o  ::qq!! Force exit from vi (discarding changes)

  +o  ::ee nnaammee Edit file _n_a_m_e

  +o  ::ee!! reedit, discard changes

  +o  ::ee ++ nnaammee edit file _n_a_m_e, starting at end

  +o  ::ee ++ nn edit starting at line _n

  +o  ::ee ## edit alternate file

  +o  ::nn edit next file in _a_r_g_l_i_s_t

  +o  ::aarrggss list files in current filelist

  +o  ::rreeww rewind current filelist and edit first file

  +o  ::nn aarrggss specify new arglist

  +o  ::ff  show current file and line

  +o  CCTTRRLL--GG synonym for :f , show current file and line

  +o  ::ttaa ttaagg  to tag file entry _t_a_g

  +o  CCTTRRLL--]]  :ta, following word is tag

  1100..77..  MMoovveemmeenntt


  +o  AArrrroowwss Move the cursor

  +o  CCTTRRLL--dd Scroll half page down

  +o  CCTTRRLL--uu Scroll half page up

  +o  CCTTRRLL--ff Scroll a full page down

  +o  CCTTRRLL--bb Scroll a full page up

  +o  ::00 Move to start of file

  +o  ::nn Move to line number n

  +o  ::$$ Move to end of file

  +o  00 Move to start of line

  +o  ^^ Move to first non-blank character

  +o  $$ Move to end of line

  +o  CCRR Move to the start of next line

  +o  -- Move to the start of previous line

  +o  %% Find matching bracket

  +o  GG  goto line (last line default)


  +o  ]]]]  next section/function

  +o  [[[[  previous section/function

  1100..88..  LLiinnee PPoossiittiioonniinngg


  +o  HH  Home window line

  +o  LL  Last window line

  +o  MM  Middle window line

  +o  ++  Next line, at first non-white

  +o  --  Previous line, at first non-white

  +o  CCRR  return, same as +

  +o  jj  next line, same column

  +o  kk  previous line, same column

  1100..99..  CChhaarraacctteerr ppoossiittiioonniinngg


  +o  00  beginning of line

  +o  $$  end of line

  +o  hh  forward

  +o  ll  backwards

  +o  SSPPAACCEE  same as l

  +o  ffxx  find x forward

  +o  FFxx  find x backward

  +o  ;;  repeat last f F

  +o  ,,  inverse of ;

  +o  ||  to specified column

  +o  %%  find matching { or }

  1100..1100..  WWoorrddss,, sseenntteenncceess,, ppaarraaggrraapphhss


  +o  ww  Word forward

  +o  bb  Word backward

  +o  ee  End of word

  +o  ))  To next sentence

  +o  ((  Back sentence

  +o  }}  To next paragraph

  +o  {{  Back paragraph


  +o  WW  Blank delimited word

  +o  BB  Back W

  +o  EE  To end of W

  1100..1111..  MMaarrkkiinngg aanndd rreettuurrnniinngg


  +o  ```` (press twice the back-quote ` key) Previous context

  +o  '.nr bi 1

     mmxx mark position with letter x

  +o  ``xx (back quote key and letter x) goto mark x

  +o

  1100..1122..  CCoorrrreeccttiioonnss dduurriinngg iinnsseerrtt


  +o  CCTTRRLL--hh Erase last character

  +o  CCTTRRLL--ww Erase last word

  +o  eerraassee  Press DELETE key, same as CTRL-h

  +o  kkiillll  Your kill key, erase input this line

  +o  \\  Escapes CTRL-h, DELETE and kill

  +o  EESSCC  Ends insertion, back to command

  +o  CCTTRRLL--??  Interrupt, terminates insert

  +o  CCTTRRLL--dd  Backtab over _a_u_t_o_i_n_d_e_n_t

  +o  CCTTRRLL--vv  Quote non-printing character

  1100..1133..  AAddjjuussttiinngg tthhee ssccrreeeenn


  +o  CCTTRRLL--ll Clear and redraw

  +o  CCTTRRLL--rr retype, eliminate @lines

  +o  zz--CCRR redraw, current line at window top

  +o  zz-- redraw, current line at window bottom

  +o  zz.. redraw, current line at window center

  +o  //ppaatt//zz-- _p_a_t line bottom

  +o  ttnn Use n line window

  +o  CCTTRRLL--ee Scroll window down 1 line

  +o  CCTTRRLL--yy Scroll window up 1 line

  1100..1144..  DDeelleettee


  +o  xx Delete the character under the cursor

  +o  XX Delete the charater before the cursor

  +o  DD Delete to the end of line

  +o  dd^^ Delete back to start of line

  +o  dddd Delete the current line

  +o  nndddd Delete _n lines starting with the current one

  +o  ddnnww Delete _n words starting from cursor

  1100..1155..  IInnsseerrtt,, cchhaannggee


  +o  ii Enter input mode inserting before the cursor

  +o  II Enter input mode inserting before the first non-blank character

  +o  aa Enter input mode inserting after the cursor

  +o  AA Enter input mode inserting after the end of the line

  +o  oo Open a new line below current line and enter input mode

  +o  OO Open a new line above current line and enter input mode

  +o  rr Replace the character under the cursor (does NOT enter input
     mode)

  +o  RR Enter input mode replacing characters

  +o  CC shift-c. Change rest of line

  +o  DD shift-d. Delete rest of line

  +o  ss Substitute chars

  +o  SS Substitute lines

  +o  JJ Join lines

  +o  JJ Join lines

  1100..1166..  CCooppyy aanndd PPaassttee

  The "yank buffer" is filled by _E_V_E_R_Y delete command, or explicitely by
  YY and yyyy.

  +o  YY Copy the current line to the yank buffer

  +o  _nyy Copy _n lines starting from the current to the yank buffer

  +o  pp Paste the yank buffer after the cursor (or below the current
     line)

  +o  PP Paste the yank buffer before the cursor (or above the current
     line)

  +o  ""_xp  Put from buffer x

  +o  ""_xy  Yank to buffer x

  +o  ""_xd  Delete into buffer x


  1100..1177..  OOppeerraattoorrss ((uussee ddoouubbllee ttoo aaffffeecctt lliinneess))


  +o  dd  delete

  +o  cc  change

  +o  <<  left shift

  +o  >>  right shift

  +o  !!  filter through command

  +o  ==  indent for LISP

  +o  yy  yank text to buffer

  1100..1188..  SSeeaarrcchh aanndd rreeppllaaccee


  +o  //_t_e_x_t Search forward for _t_e_x_t

  +o  ??_t_e_x_t Search backward for _t_e_x_t

  +o  nn Repeat the last search in the same direction

  +o  NN Repeat the last search in the reverse direction

  +o  // Repeat the last search forward

  +o  ?? Repeat the last search backward

  +o  [[ aaddddrr ]] ss//ffrroomm//ttoo// [[ gg ]]  Search for the occurence of _f_r_o_m and
     replace it with _t_o in the current line, or in the range _a_d_d_r (two
     line numbers seperated by command; 1,$ is the whole file).
     Replaces one occurrence per line, or all occurrences if _g is
     specified.  For example, :3,20s/someword/anotherword/g  Will
     replace "someword" with "anotherword" starting from line 3 to line
     20. 'g' is global means replace all occurrences of "someword".

  1100..1199..  GGeenneerraall


  +o  ::sshh Forks a shell (to be exited with CTRL-d)

  +o  ::!!_c_o_m_m_a_n_d Forks a shell to execute _c_o_m_m_a_n_d

  +o  ::sseett nnuummbbeerr Switch on line numbering

  +o  ::sseett nnoonnuummbbeerr Switch off line numbering

  1100..2200..  LLiinnee EEddiittoorr CCoommmmaannddss


  +o  :: Tells vvii that the next commands you issue will be line editor
     commands.

  +o  ::sshh Temporarily returns to the shell to perform some shell commands
     without leaving vvii.

  +o  CCTTRRLL--dd Escapes the temporary return to the shell and returns to vvii
     so you can edit the current window.

  +o  ::_n Goes to the _nth line of the buffer.


  +o  ::_x_,_zww _f_i_l_e_n_a_m_e Writes lines from the numbers _x through the number _z
     into a new file called _f_i_l_e_n_a_m_e.

  +o  ::$$ Moves the cursor to the beginning of the last line in the
     buffer.

  +o  ::..,,$$dd Deletes all the lines from the current line to the last line

  +o  ::rr _f_i_l_e_n_a_m_e Inserts the contents of the file _f_i_l_e_n_a_m_e under the
     current line of the buffer.

  +o  ::ss_/_t_e_x_t_/_n_e_w___t_e_x_t_/ Replaces the first instance of _t_e_x_t on the
     current line with _n_e_w___t_e_x_t

  +o  ::ss_/_t_e_x_t_/_n_e_w___t_e_x_t_/_g Replaces the every occurrence of _t_e_x_t on the
     current line with _n_e_w___t_e_x_t

  +o  ::gg_/_t_e_x_t_/_s_/_/_n_e_w___t_e_x_t_/_g Changes every occurrence of _t_e_x_t on the
     buffer to _n_e_w___t_e_x_t.

  1100..2211..  OOtthheerr ccoommmmaannddss


  +o  uu Undo the last change

  +o  UU Restore the current line

  +o  ~~ Change case

  +o  JJ Join the currentline with the next line

  +o  .. Repeat last text changing command

  +o  CCTTRRLL--gg Show file name and line number

  1111..  OOtthheerr FFoorrmmaattss ooff tthhiiss DDooccuummeenntt

  This document is published in 10 different formats namely - DVI,
  Postscript, Latex, LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-
  text, Unix man pages and SGML.

  +o  You can get this HOWTO document as a single file tar ball in HTML,
     DVI, Postscript or SGML formats from -
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO/other-formats/> or
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO/other-formats/>

  +o  Plain text format is in:
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO> or
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO>

  +o  Translations to other languages like French, German, Spanish,
     Chinese, Japanese are in
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO> or
     <ftp://metalab.unc.edu/pub/Linux/docs/HOWTO> Any help from you to
     translate to other languages is welcome.

     The document is written using a tool called "SGML tool" which can
     be got from - <http://www.xs4all.nl/~cg/sgmltools/> Compiling the
     source you will get the following commands like

  +o  sgml2html vim-howto.sgml     (to generate html file)

  +o  sgml2rtf  vim-howto.sgml     (to generate RTF file)

  +o  sgml2latex vim-howto.sgml    (to generate latex file)

  This document is located at -

  +o  <http://metalab.unc.edu/LDP/HOWTO/VIM-HOWTO.html>

  Also you can find this document at the following mirrors sites -

  +o  <http://www.caldera.com/LDP/HOWTO/VIM-HOWTO.html>

  +o  <http://www.WGS.com/LDP/HOWTO/VIM-HOWTO.html>

  +o  <http://www.cc.gatech.edu/linux/LDP/HOWTO/VIM-HOWTO.html>

  +o  <http://www.redhat.com/linux-info/ldp/HOWTO/VIM-HOWTO.html>

  +o  Other mirror sites near you (network-address-wise) can be found at
     <http://metalab.unc.edu/LDP/hmirrors.html> select a site and go to
     directory /LDP/HOWTO/VIM-HOWTO.html


  In order to view the document in dvi format, use the xdvi program. The
  xdvi program is located in tetex-xdvi*.rpm package in Redhat Linux
  which can be located through ControlPanel | Applications | Publishing
  | TeX menu buttons.


               To read dvi document give the command -
                       xdvi -geometry 80x90 howto.dvi
               And resize the window with mouse. See man page on xdvi.
               To navigate use Arrow keys, Page Up, Page Down keys, also
               you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter
               keys to move up, down, center, next page, previous page etc.
               To turn off expert menu press 'x'.




  You can read postscript file using the program 'gv' (ghostview) or The
  ghostscript program is in ghostscript*.rpm package and gv program is
  in gv*.rpm package in Redhat Linux which can be located through Con-
  trolPanel | Applications | Graphics menu buttons. The gv program is
  much more user friendly than ghostscript.  Ghostscript and gv are also
  available on other platforms like OS/2, Windows 95 and NT.


               To read postscript document give the command -
                       gv howto.ps

               To use ghostscript give -
                       ghostscript howto.ps




  You can read HTML format document using Netscape Navigator, Microsoft
  Internet explorer, Redhat Baron Web browser or any other web browsers.

  You can read the latex, LyX output using LyX a "X-Windows" front end
  to latex.








