rom1@catsrule.garfield.com
Copyright © 2001 by Romain Lerallut
Revision History | ||
---|---|---|
Revision v0.05 | 11 January 2002 | Revised by: rml |
Applies D-Man's patch for typos and some vim stuff. | ||
Revision v0.04 | 30 May 2001 | Revised by: rml |
Changes in the title page. | ||
Revision v0.03 | 24 May 2001 | Revised by: RL |
One more tip, and the FDL License. VI Rules ever more!! | ||
Revision v0.02 | 23 February 2001 | Revised by: RL |
Application of Tom Huckstep's patch and slight modifs. VI Rules even more!! | ||
Revision v0.01 | 11 January 2001 | Revised by: RL |
First draft of the SGML-based version. VI Rules!! |
I wish to extend my thanks to the all the doc writers of the NewbieDoc Project, and to those who submitted patches to make this doc better (most notably DMan whose patch staid there, forgotten, for quite some time...). And also to Tom Huckstep for his SGML templates and detailed howto, his patch(es ?) and of course to Will Trillich for starting this whole thing.
Thanks...
You can start vi by typing vi alone (that wasn't hard to figure out, was it ?),
or you can specify a filename: vi hop.txt
Written for Xucaen and all the ones who ever got stuck in the vi quicksands :-)
Sometimes people start vi "just to see what it looks like" and can't find how to getout !!
There are tons of ways to move the cursor around, so I'll just give the basic ones:
Now that you can move the cursor around, let's see how you can type text:
When in insert mode, you can delete only the text you've just insered.To delete other parts of the file, get out of insert mode (ESC) and go toDeleting Text
![]() | Vim specific: If you add the following command to your ~/.vimrc or type it while running vim you will be able to backspace through the entire buffer, not just the text entered during the current "input session". :set backspace=2 |
When you delete text that has just been inserted, see that the letters aren't erased from the screen. Instead the cursor just moves backwards and what you type will overwrite what you had "deleted". Just get used to it.
![]() | Vim specific: This occured in original vi, and apparently in some modern clones (it was probably originally due to lack of processing power). In vim this isn't a problem -- all the characters you delete will disappear immediately, except perhaps when being used over a slow dialup line, but then the problem is the dialup line and not vi(m). |
Most common insertion commands, all the following commands will get you in insert mode, but in different ways:
Appending (a): insert text after current cursor position
Inserting (i): insert text before current cursor position
Open New Line (o): open new line below current line and insert
All those commands have their counterparts in capital letters:
Appending at end of line (A): insert text after last character on the line
Inserting at beginning of line (I): insert text before first non blanck character on the line
Open New Line (O): open new line above current line and insert
![]() | N.B.: insertion (as well as most commands) can be combined with a "multiplier", in the same way than cursor commands: |
10a(type your text...) will repeat 10 times the command a. So vi will append the text you've just typed in ten times.
![]() | Deletion can be combined with a "multiplier", in the same way as cursor commands: 10dd will delete 10 lines |
![]() | Deleted text will be stored in the 'yank' buffer, replacing the previous one. (see Yanking and Pasting) |
WARNING: entering insert mode will erase the yank buffer.
![]() | Vim specific: Vim doesn't erase the yank buffer when you enter insert mode. |
:line1,line2command |
:1,20y |
:1,$d |
:%d |
:line1,line2s/old_string/new_string/g |
\r\n = chr(13)chr(10) = MS-DOS
Our MSDOS text file should look like this:
Friday the 13th^M ^M ^M ^M Dear Sir,^M ^M .... |
And our mac text file should look like that
"Friday the 13th^M^M^MDearSir,^M^M...." |
MS-DOS/Windows -> UNIX conversion:
In order to remove these ugly ^M, you search for them and replace them by....nothing!
So first, let's search for those weird ^M ... but, how can you search for character 'ENTER'?
:1,$s/^V^M// |
(where ^V is Control-V, and ^M is ENTER or Control-M)
note that VI doesn't display the ^V, so you'll only see
:1,$s/^M// |
Info about current file: Ctrl-g will display info about the current file
Line numbers: :set nu to display line numbers and :set nonu to not display them.
Useful Stuff For Writing Code or Newbiedoc HOW-TOs
:set expandtab softtabstop=4 shiftwidth=4 |