$Header: /repository/documentation/vi.htm,v 1.2 2006/04/29 00:24:44 joerg Exp $
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.
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
'i') switch
into the input mode. the command : switches into ex-mode. if you submit the
ex command
with RETURN, you are back in command-mode. it's the best
vi-secret, when the
input-mode switches back to command-mode. but with ESC 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 ESC.
so normally you work like this:
ESC:, then ex-command, then RETURN i, R, c, o, a you are put into input-mode.many commands have a general common behavior:
'd' (delete data).'dd'): delete whole lineD delete rest of lineexamples:
'G' goes to last line: 'dG' deletes all up
to the last line'34G' goes to line number 34: 'd34G' deletes
everything up to
line 34'`a' goes to mark named a: 'd`a' deletes
everything until
mark a.'w' moves to next word: 'dw' deletes next
word.'n' moves to next search result: 'dn'
deletes everything up to
next find result.'/copy' goto the next occurrence of copy:
'd/copy' delete
everything up to the next word copy.all these examples work for several commands:
c - change texty - copy textd - delete text(for example: 'y1G': copy text from cursor to beginning of
text).
you can preface these commands (as well as the 'p' command)
with '"<a>'
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 ':n' or ':e'. for example:
'"adG'
delete until the end of file and put text into buffer named a.
'"ap':
paste buffer a into text. if you use capital buffernames text is appended to
the buffer.
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:
at the beginning position of the area to be deleted enter
'ma' (set mark
with name a)
with scrolling, or find or whatever goto the end position of the to be deleted area
enter 'd`a' (unfortunately the '`' (backquote) on my pc is
entered via
SHIFT-` SPACE)
in your home directory (which is the dir where you are placed by just
entering 'cd'
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:
set number
set showmode
set noautoindent
number shows the line numbers. showmode sometimes shows when you are in
input mode. and
noautoindent protects you from endless armadas of tab-chars. ('set
number' is
surely the most important).
i made a list of useful commands. the idea is to learn the commands in the sequence of the list.
:w |
write file |
ZZ |
write and exit file |
:q! |
exit vi without save |
:q |
exit file |
i |
insert text |
a |
insert text after actual char |
A |
insert text at end of line |
r |
replace one char |
R |
replace many chars (use ESC to end) |
x |
delete char |
dd |
delete line |
/hugo |
search for the string 'hugo' |
?hugo |
search for the string 'hugo' backward |
n |
repeat last search |
N |
repeat last search in the oposit direction |
1,$s/hugo/victor/g |
change all occurences of 'hugo' to 'victor' |
D |
delete rest of line |
o |
append new line after actual line |
O |
append new line before actual line |
yy |
copy line to buffer |
23yy |
copy 23 lines to buffer |
p |
put lines from buffer after actual line |
y234G |
copy all line from actual until linenumber 234 |
"add |
delete line and put to buffer a |
"Add |
delete line and append to buffer a |
"ap |
put text from buffer a |
"by4w |
copy next 4 words into buffer b |
0 |
beginning of line |
+ |
beginning of next line |
- |
beginning of previous line |
w |
next word |
b |
previous word |
z+ z. z- |
actual line on top, middle or bottom of screen |
c |
change text |
cc |
change current line |
C |
change until end of line |
ma |
define mark with name a |
'a |
goto line with mark a |
`a |
go exactly to mark a |
d'a |
delete from actual line until line with mark a |
% |
goto corresponding (, [ or { |
'' |
go back to old actual line |
. |
repeat last change command |
abbrev re return |
when typing re it's replaced by return |
this web page was designed by joerg kunze.
copyright; 1999, 2006 joerg kunze
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.
this web page is distributed in the hope that it is useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. see the GNU General Public License for details.
you should have received a copy of the GNU General Public License along with these web page; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
$Log: vi.htm,v $
Revision 1.2 2006/04/29 00:24:44 joerg
add Header and Log cvs keywords