Part of
the 22C:50 System Software support pages
by
Douglas W. Jones
THE UNIVERSITY
OF IOWA
Department of Computer Science
The vi editor and its clones elvis, vim, vile, nvi
and several others are commonly found editors on various versions of Unix,
Linux and
related systems; vi is now routinely shipped with MacOS X and there are
versions available for Windows.
The purpose of the material presented here is not to make you an expert,
but rather, to get you off the ground in a powerful but sometimes difficult
to learn editor.
There are many much longer tutorials that try to make you a vi expert; the
vi lovers home page has
a good index of these.
Vi is designed with several interesting features that speed editing for experienced users but can be very frustrating for beginners:
There are several common problems that occasionally plague even the most experienced vi user:
Notes the return or enter key [CR] the escape key [ESC] Launching vi from the command line to edit file.txt vi file.txt[CR] Cursor movement left h (may use arrow keys) down j up k right l (or space) to next word w to previous word b to start of next line [CR] to line 55 of the file :55[CR] to end of the file :$[CR] Search to next xxx in file /xxx[CR] to previous xxx in file ?xxx[CR] match xpx or xqx or xrx /x.x[CR] match xx or xyx or xyyyx /xy*x[CR] match only xax or xbx /x[ab]x[CR] Undo undo last change u Save Changes and Exit save changes :w[CR] save to temp.c :w temp.c[CR] exit :q[CR] force exit without saving :q![CR] Yank (copy) text into cut-paste buffer current word yw current line yy next 5 lines 5yy Delete text (cut into cut-paste buffer) current character x current word dw to end of line D current line dd next 5 lines 5dd all lines containing xxx :1,$g/xxx/d[CR] Paste from cut-paste buffer after this character or line p (lower case) before this character or line P (upper case) Insert text into file append xxx after cursor axxx[ESC] append xxx at end of this line Axxx[ESC] insert xxx before cursor ixxx[ESC] insert xxx at start of this line Ixxx[ESC] from temp.txt after this line :r temp.txt[CR] Replace current character with x rx next few characters with xxx Rxxx[ESC] on this line, all xxx with yy :s/xxx/yy/g[CR] globally, all xxx with yy :1,$g/xxx/s//yy/g[CR]