<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>New Page 1</TITLE>
<META NAME="GENERATOR" CONTENT="Microsoft FrontPage 3.0">
</HEAD>
<BODY>
<H1>siliconbrain's small vi survival guide</H1>
<pre>
$Header: /repository/documentation/vi.htm,v 1.2 2006/04/29 00:24:44 joerg Exp $
</pre>
<H2>why</H2>
<P>sometimes unfortunatly and no one knows why, you have to work on
something similar to a
computer, but with no emacs. all the crying does not help: you have to use
vi. to prevent
you from going crazy and becomming lunatic, i provided this little vi
survival guide. </P>
<H2>modes</H2>
<P>vi has three modes: command-mode, ex-mode and input-mode. the
command-mode is the
normal mode in which you should be normally. some commands (like
<CODE>'i'</CODE>) switch
into the input mode. the command : switches into ex-mode. if you submit the
ex command
with <CODE>RETURN</CODE>, you are back in command-mode. it's the best
vi-secret, when the
input-mode switches back to command-mode. but with <CODE>ESC</CODE> you can
force
command-mode. if you are not sure if you are in command- or input-mode (what
is almost
always the case), just press <CODE>ESC</CODE>.</P>
<P>so normally you work like this:
<UL>
<LI>enter vi</LI>
<LI>do some commands.</LI>
<LI>do an input command, then input text, then <CODE>ESC</CODE></LI>
<LI><CODE>:</CODE>, then ex-command, then <CODE>RETURN</CODE></LI>
<LI>with<CODE> i, R, c, o, a</CODE> you are put into input-mode.</LI>
</UL>
<H2>commands</H2>
<P>many commands have a general common behavior:
<UL>
<LI>press it once, then the command waits for the definition for the
target location. for
example <CODE>'d'</CODE> (delete data).</LI>
<LI>target same as command (<CODE>'dd'</CODE>): delete whole line</LI>
<LI>type command in capital: <CODE>D</CODE> delete rest of line</LI>
<LI>type a cursor move command as target.</LI>
</UL>
<P>examples:
<UL>
<LI><CODE>'G'</CODE> goes to last line: <CODE>'dG'</CODE> deletes all up
to the last line</LI>
<LI><CODE>'34G'</CODE> goes to line number 34: <CODE>'d34G'</CODE> deletes
everything up to
line 34</LI>
<LI><CODE>'`a'</CODE> goes to mark named a: <CODE>'d`a'</CODE> deletes
everything until
mark a.</LI>
<LI><CODE>'w'</CODE> moves to next word: <CODE>'dw'</CODE> deletes next
word.</LI>
<LI><CODE>'n'</CODE> moves to next search result: <CODE>'dn'</CODE>
deletes everything up to
next find result.</LI>
<LI><CODE>'/copy'</CODE> goto the next occurrence of copy:
<CODE>'d/copy'</CODE> delete
everything up to the next word copy.</LI>
</UL>
<P>all these examples work for several commands:
<UL>
<LI><CODE>c</CODE> - change text</LI>
<LI><CODE>y</CODE> - copy text</LI>
<LI><CODE>d</CODE> - delete text</LI>
</UL>
<P>(for example: <CODE>'y1G'</CODE>: copy text from cursor to beginning of
text).</P>
<P>you can preface these commands (as well as the <CODE>'p'</CODE> command)
with <CODE>'"<a>'</CODE>
where <a> is one of the 26 chars of the alphabet or a number. if you
do that the
deleted or copied text is put into the named buffers. named buffers are
kept, when you
change the file via <CODE>':n'</CODE> or <CODE>':e'</CODE>. for example:
<CODE>'"adG'</CODE>
delete until the end of file and put text into buffer named a.
<CODE>'"ap'</CODE>:
paste buffer a into text. if you use capital buffernames text is appended to
the buffer.</P>
<P>if you want to delete from where the cursor is up to a place which you
don't know, and
you have to search it via scrolling and finding you can proceed as
following:</P>
<P>at the beginning position of the area to be deleted enter
<CODE>'ma'</CODE> (set mark
with name a)</P>
<P>with scrolling, or find or whatever goto the end position of the to be
deleted area</P>
<P>enter <CODE>'d`a'</CODE> (unfortunately the '`' (backquote) on my pc is
entered via
SHIFT-` SPACE)</P>
<H2>the .exrc</H2>
<P>in your home directory (which is the dir where you are placed by just
entering <CODE>'cd'</CODE>
without any target-dir), you can have a file named '.exrc'. this file is
executed when the
vi is started. it can contain ex-commands. i recommend the following
contents:</P>
<PRE><CODE>set number
set showmode
set noautoindent</CODE></PRE>
<P>number shows the line numbers. showmode sometimes shows when you are in
input mode. and
noautoindent protects you from endless armadas of tab-chars. (<CODE>'set
number'</CODE> is
surely the most important). </P>
<H2>the command list</H2>
<P>i made a list of useful commands. the idea is to learn the commands in
the sequence of
the list. </P>
<TABLE BORDER="l">
<TR>
<TD> <CODE>:w</CODE></TD>
<TD>write file</TD>
</TR>
<TR>
<TD><CODE>ZZ </CODE></TD>
<TD>write and exit file</TD>
</TR>
<TR>
<TD><CODE>:q! </CODE></TD>
<TD>exit vi without save</TD>
</TR>
<TR>
<TD><CODE>:q </CODE></TD>
<TD>exit file</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>i </CODE></TD>
<TD>insert text</TD>
</TR>
<TR>
<TD><CODE>a </CODE></TD>
<TD>insert text after actual char</TD>
</TR>
<TR>
<TD><CODE>A </CODE></TD>
<TD>insert text at end of line</TD>
</TR>
<TR>
<TD><CODE>r </CODE></TD>
<TD>replace one char</TD>
</TR>
<TR>
<TD><CODE>R </CODE></TD>
<TD>replace many chars (use ESC to end)</TD>
</TR>
<TR>
<TD><CODE>x </CODE></TD>
<TD>delete char</TD>
</TR>
<TR>
<TD><CODE>dd </CODE></TD>
<TD>delete line</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>/hugo</CODE></TD>
<TD>search for the string 'hugo'</TD>
</TR>
<TR>
<TD><CODE>?hugo</CODE></TD>
<TD>search for the string 'hugo' backward</TD>
</TR>
<TR>
<TD><CODE>n</CODE></TD>
<TD>repeat last search</TD>
</TR>
<TR>
<TD><CODE>N</CODE></TD>
<TD>repeat last search in the oposit direction</TD>
</TR>
<TR>
<TD><CODE>1,$s/hugo/victor/g</CODE></TD>
<TD>change all occurences of 'hugo' to 'victor'</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>D </CODE></TD>
<TD>delete rest of line </TD>
</TR>
<TR>
<TD><CODE>o </CODE></TD>
<TD>append new line after actual line</TD>
</TR>
<TR>
<TD><CODE>O </CODE></TD>
<TD>append new line before actual line</TD>
</TR>
<TR>
<TD><CODE>yy </CODE></TD>
<TD>copy line to buffer</TD>
</TR>
<TR>
<TD><CODE>23yy </CODE></TD>
<TD>copy 23 lines to buffer</TD>
</TR>
<TR>
<TD><CODE>p </CODE></TD>
<TD>put lines from buffer after actual line</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>y234G </CODE></TD>
<TD>copy all line from actual until linenumber 234</TD>
</TR>
<TR>
<TD><CODE>"add </CODE></TD>
<TD>delete line and put to buffer a</TD>
</TR>
<TR>
<TD><CODE>"Add </CODE></TD>
<TD>delete line and append to buffer a</TD>
</TR>
<TR>
<TD><CODE>"ap </CODE></TD>
<TD>put text from buffer a</TD>
</TR>
<TR>
<TD><CODE>"by4w </CODE></TD>
<TD>copy next 4 words into buffer b</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>0 </CODE></TD>
<TD>beginning of line</TD>
</TR>
<TR>
<TD><CODE>+ </CODE></TD>
<TD>beginning of next line</TD>
</TR>
<TR>
<TD><CODE>- </CODE></TD>
<TD>beginning of previous line</TD>
</TR>
<TR>
<TD><CODE>w </CODE></TD>
<TD>next word</TD>
</TR>
<TR>
<TD><CODE>b </CODE></TD>
<TD>previous word</TD>
</TR>
<TR>
<TD><CODE>z+ z. z- </CODE></TD>
<TD>actual line on top, middle or bottom of screen</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>c </CODE></TD>
<TD>change text</TD>
</TR>
<TR>
<TD><CODE>cc </CODE></TD>
<TD>change current line</TD>
</TR>
<TR>
<TD><CODE>C </CODE></TD>
<TD>change until end of line</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>ma </CODE></TD>
<TD>define mark with name a</TD>
</TR>
<TR>
<TD><CODE>'a </CODE></TD>
<TD>goto line with mark a</TD>
</TR>
<TR>
<TD><CODE>`a </CODE></TD>
<TD>go exactly to mark a</TD>
</TR>
<TR>
<TD><CODE>d'a </CODE></TD>
<TD>delete from actual line until line with mark a</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD><CODE>% </CODE></TD>
<TD>goto corresponding (, [ or {</TD>
</TR>
<TR>
<TD><CODE>'' </CODE></TD>
<TD>go back to old actual line</TD>
</TR>
<TR>
<TD><CODE>. </CODE></TD>
<TD>repeat last change command</TD>
</TR>
<TR>
<TD><CODE>abbrev re return </CODE></TD>
<TD>when typing re it's replaced by return</TD>
</TR>
</TABLE>
<HR>
<P> <A HREF="index.htm">the silicon brain home page</A> </P>
<P> <A HREF="mailto:info@siliconbrain.com">contact
SiliconBrain</A></P>
<ADDRESS>
<A HREF="mailto:info@siliconbrain.com">info@siliconbrain.com</A>
</ADDRESS>
<P> this web page was designed by joerg kunze.</P>
<P> copyright; 1999, 2006 joerg kunze </P>
<P> this web page is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the license or (at your opinion) any later version.</P>
<P> this web page is distributed in the hope that it is useful, but
<STRONG>without any warranty</STRONG>; without even the implied warranty of
<STRONG>merchantability</STRONG> or <STRONG>fitness for a particular
purpose</STRONG>. see the GNU General Public License for details.</P>
<P> you should have received a <A HREF="gpl.html">copy of the GNU
General Public License</A>
along with these web page; if not, write to the
<A HREF="http://www.fsf.org/">Free Software Foundation</A>, Inc.,
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.</P>
<hr>
<pre>
$Log: vi.htm,v $
Revision 1.2 2006/04/29 00:24:44 joerg
add Header and Log cvs keywords
</pre>
</BODY>
</HTML>