WPI Mathematical Sciences Department

Mathematical Sciences WWW Server



vi (VIsual display editor)

by Joseph D. Fehribach   < bach@wpi.edu >

The commands are divided into three sections.


Starting vi

   
  This file contains a list of what the keys do in vi.  The first section
  deals with start-up options.  The format needed to start  vi  at the UNIX
  prompt is

                 vi  filename

  or if you want to get fancy

                 vi  options  filename

  where the possible options are

Options        Description

  -R           enter  vi  in Read-only mode (same as view)
  +            enter  vi  on the last line of the file
  +n           enter  vi  on the "n"th line of the file
  +/x          enter  vi  at the first occurrence of "x"
  -r           enter  vi  with a buffer, presumably after a system/network
               failure (Recover)

Command mode

 
Command        Description

SPACE-BAR      advance the cursor one SPACE
  l            advance the cursor one SPACE (same as right arrow)
  h   	       backspace the cursor (same as left arrow or CTRL-h)
  j   	       move down to Next line (same as down arrow or CTRL-n)
  k   	       move up to Previous line (same as up arrow or CTRL-p)

CTRL-B         scroll Backward one window
CTRL-F	       scroll Forward one window
CTRL-D         scroll Down in the file half a window
CTRL-U	       scroll Up in the file half a window

  b            move the cursor Back a word or punctuation character
  B            move the cursor Back one word, ignoring punctuation
  e            move the cursor to the End of the current word
  E            move the cursor to End of current word, ignoring punctuation
  w            move the cursor forward a Word or punctuation character
  W            move the cursor forward one Word, ignoring punctuation

RETURN         move down to next line, at beginning of line (same as +)
  -            move up to previous line, at the beginning of the line

  H            move the cursor to the top (or Head) of the window
  M            move the cursor to the Middle screen line
  L            move the cursor to the Last screen line
  nH           move the cursor "n" lines above the Head screen line
  nL           move the cursor "n" lines below the Last screen line

  ^            move cursor to first non-blank character of current line 
  0            move cursor to first character of current line (blank or not)
  $            move cursor to end of line
  )            move cursor forward one sentence
  (            move cursor backward one sentence
  }            move cursor forward one paragraph
  {            move cursor backward one paragraph
  ]]           move cursor forward one section
  [[           move cursor backward one section

CTRL-E         Exposes another line at bottom of the window
CTRL-Y	       expose another line at the top of the window

CTRL-G	       general info, "was Gibt es?" (file name, cursor location, etc.)
  G            Go to last line in file
  nG           Go to "n"-th line in file

  mx           place Marker "x" at cursor location
  `x           goto location of marker "x" 
  'x           goto first non-blank character in line containing marker "x" 

  /            scan forward in the file for the following string
  ?            scan backward in the file for the following string
  n            scan through file for Next instance of / or ? pattern
  N            scan through file in opposite direction for / or ? pattern

  A            Appends text at the end of the current line
  a            Appends text after the cursor
  I            Inserts text at the beginning of the line
  i            Inserts text before the cursor
  O            Opens and inputs new lines, above the current line
  o            Opens and inputs new lines, below the current line
  R            Replace characters (overwrite mode)
  r            Replace a single character

  C            Change to end of line (same as c$)
  cw           Change text from cursor to end of Word (same as ce)
  D            Delete to end of line (same as d$)
  dw           Delete text from cursor to end of Word (same as ce)
  dd           Delete the entire line
  ndd          Delete "n" lines
  s            Substitute for character under cursor
  S            change entire current line (same as cc)
  sn           Substitute for "n" characters 
  cnw          Change text from cursor through "n" Words (same as cne, ncw)
  dnw          Delete text from cursor through "n" Words (same as dne, ndw)

  J            Join the current line with the following line

  x            delete (X-out) character under cursor
  X            delete (X-out) character before cursor

  .            repeats the last change at the present cursor location
  U            Undoes the changes you made to the current line
  u            Undoes the last change

  fx           Find "x" forward in line
  Fx           Find "x" backward in line
  tx           move forward To "x" in the line
  Tx           move backward To "x" in the line

  dfx          Delete Forward through "x" (including "x")
  dtx          Delete To "x" (not including "x")
  cfx          Change Forward through "x" (including "x")
  ctx          Change To "x" (not including "x")

  ;            repeat last f, F, t or T
  ,            inverse of ;

  P            Put text back, before cursor or above current line
  p            Put text back, after cursor or below current line
  Y            Yank one line into buffer (same as yy)
  y            Yank the object you specify into buffer; for copies and moves

  ZZ           end session, saving all changes (same as :wq and :x)

  :w           Write (save) file to disk
  :w!          forced Write; overwites existing file, overrides some
               permission restrictions
  :w newfile   Write (save) file to disk as NEWFILE

  :q           Quit session (only works if there are no unsaved changes)
  :q!          forced Quit; all unsaved changes are lost

  :wq          Write and Quit
  :x           eXit (same as :wq and ZZ)
  :wq!         forced Write and Quit
  :x!          forced eXit (same as :wq!)

  :e newfile   Edit NEWFILE (only works if there are no unsaved changes)
  :e! newfile  Edit NEWFILE; unsaved changes to current file are lost
  :e#          Edit the previous file (only works if no unsaved changes exist)
  :e!          restart Edit of current file; all unsaved changes are lost
  :e!#         Edit the previous file; unsaved changes to current file are lost

  :set         show which options have been reSET from default setting
  :set all     show ALL SETable options (useful in seeing what options exist)
  :set op?     show the value of OPtion (example: ":set redraw?" )
  :set op      SET a toggle OPtion on (example: ":set redraw" )
  :set noop    SET a toggle OPtion off (example: ":set noredraw" )
  :set op=valu SET an OPtion equal to VALUe

  :!command    execute a single shell COMMAND inside of vi
  :sh          open a SHell inside of vi (default shell)
  :!tcsh       open a T-SHell inside of vi
  :!csh        open a C-SHell inside of vi

  :r file      Read FILE into buffer on line after cursor
  :nr file     Read FILE into buffer after line "n"
  :0r file     Read FILE into top of buffer
  :$r file     Read FILE into bottom of buffer
  :/pat/r file Read FILE into buffer after next occurrence of PATtern

Insert mode

Command        Description

CTRL-I         same as TAB
CTRL-W         erase a Word during an insert
DEL            erase character (or CTRL-H), erases during an insert
CTRL-U         your kill character (or CTRL-X), kills the insert on this line



Maintained by: ma-questions@wpi.edu
Last Updated: 9 April 1999